Discover Auto Increment ID After MySQL Insert With PHP
Discover Auto Increment ID After MySQL Insert With PHP
9th March 2008 - 2 minutes read time
Note: This post is over a year old and so the information contained here might be out of date. If you do spot something please leave a comment and we will endeavour to correct.
Inserting a value into a database with an auto incrementing field is quite common. Once you insert the new row you would expect that you need to do another query to get the newly created ID.
Another option is to use the mysql_insert_id() function to retrieve the ID created by the last insert statement.
// insert
$sql = 'INSERT INTO table(colum1, colum2) VALUES(1, 2);';
mysql_query($sql);
// get new id
$id = mysql_insert_id();
The $id variable will now contain your most recently inserted ID.
Generating a PDF document from a web page through PHP can be problematic. It's often something that seems quite simple, but actually generating the document can be difficult and time consuming.
Reflection is used to gather more information about code during the runtime of the program. This allows code to inspect itself and to make small modifications, which is useful in a variety of situations.
PHP 8.1 comes with a few new additions to the language, and one that I have seen get the most attention is fibers. This is a feature that allows PHP code to be executed in a concurrent thread, with the ability to pause and resume that code at will.