mysql_insert_id();
An example using a temporary table is shown here:
<?php $conn = mysql_connect('localhost', 'username', 'password') or die ('Error connecting to mysql'); mysql_select_db('myDatabase'); mysql_query("CREATE TEMPORARY TABLE testTable (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), column1 VARCHAR(50) )") or die (mysql_error()); mysql_query("INSERT INTO testTable VALUES ()"); $id = mysql_insert_id(); echo $id; //Outputs 1 mysql_query("INSERT INTO testTable VALUES ()"); $id = mysql_insert_id(); echo $id; //Outputs 2 ?>
Simple and useful PHP ;)
I use a temporary table in the example to demonstrate the concept, so that in case you do decide to test out the example, it will not leave a footprint on your MySQL server, since temporary tables are deleted when the MySQL session is over.
Thanks - that's something I didn't know about! just FYI there is also a LAST_INSERT_ID() mysql function that does a similar thing from the command line
ReplyDeletemysql> SELECT LAST_INSERT_ID();
I find it pretty useful sometimes!
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
0Aİ
salt likit
ReplyDeletesalt likit
dr mood likit
big boss likit
dl likit
dark likit
QDİF