Sep 24, 2012

How to find id of last inserted row in MYSQL using PHP


 



To find id (auto increment) value of last inserted row, put the following code into the PHP page.



<?php



$link = mysql_connect('localhost', 'mysql_usenamer', 'mysql_password');


if (!$link) {


    die('Could not connect:to the database ' . mysql_error());


}


mysql_select_db('mydb');


 


mysql_query("INSERT INTO mytable (user) values ('jijo')");


printf("Last inserted record has id %d\n", mysql_insert_id());


?>





No comments:

Post a Comment