How to get the mysql last inserted id using PHP?

We have to easily get the last inserted id in mysql table using below code.


$connection = mysql_connect('localhost', 'MYSQL_USERNAME', 'MYSQL_PASSWORD') or mysql_error();

mysql_select_db('DATABASE_NAME', $connection)  or mysql_error();

$query = "INSERT INTO emp_table (emp_id, emp_name, emp_qualification, emp_salary) VALUES ('SC70699', 'Ramakrishnan', 'MCA', '13186')";

mysql_query($query );

$last_insert_id = mysql_insert_id();

echo "Last insert id in employee table: ".$last_insert_id;

mysql_close($connection) ;


1 comment:

  1. I delight in, lead to I discovered just what I used to be having a look for. You've ended my 4 day long hunt! God Bless you man. Have a great day. Bye
    20lb Bulk Pig Ear Strips