How to get last inserted record ID in mysql?

How to get last inserted record ID in mysql?

mysql_insert_id function is used to "Get the ID generated from the previous INSERT operation"
How to use the function?
Example code:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
?>

No comments: