Getting an auto-incremented value from a MySQL database
I am writing a PHP script where data is inserted into a table using a query l开发者_JAVA百科ike "INSERT INTO y (x, x, x) VALUES (z, z, z). I have a unique, primary, auto-incrementing key that is in the table. How can I fetch that number right after the data is inserted and the key is updated with the new row?
mysql_insert_id
more information and example of use: http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
Depends on how you are making the queries, if you are using some DB abstraction layer or not...
mysql functions: mysql_insert_id
mysqli: mysqli->insert_id
PDO: PDO::lastInsertId
mysql_insert_id — Get the ID generated in the last query
精彩评论