I'm inserting a row into a table, like so:
mysql_query("INSERT INTO post(name,message,date)VALUES('$name','$mes开发者_Python百科sage','$date')");
The table 'post' has an auto-incremented int column, called 'postInt'. How do easily get this int of the just-created row?
You can call mysql_insert_id()
mysql_insert_id — Get the ID generated in the last query
Just make sure to call this method immediately after you run the INSERT
query because this method will act on the last performed query.
http://nl.php.net/manual/en/function.mysql-insert-id.php
This is mysql version.
select last_insert_id()
printf("Last inserted record has id %d\n", mysql_insert_id());
精彩评论