Saturday 19 January 2019

mysql - How to obtain the last inserted auto increment id using PDO library?




I have a table that of course has a unique id for each entry.




How can I retrieve that id when I do a simple insert using this query string:



"INSERT INTO lion_is_foob (id_user, title, url, domain, tag, favicon) VALUES (?, ?, ?, ?, ?, ?)"


The column name is called id for the auto increment.



Because an insert so commonly creates an auto ID can I retrieve this at the same time.


Answer




Look at http://php.net/mysql_insert_id or http://php.net/mysqli_insert_id (depending on which set of MySQL functions you're using).


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...