开发者

Getting auto-incremented int from just created row?

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());

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜