note 14566 deleted from function.mysql-insert-id by cmb
| From: | cmb@php.net | Date: | Sun, 16 Feb 2020 13:33:32 +0000 |
| Subject: | note 14566 deleted from function.mysql-insert-id by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214122@lists.php.net to get a copy of this message | ||
Note Submitter: frumler at the-beach dot no_spam dot net
----
If you want to use the ID that was generated for one table and insert it into a second table, you
can use SQL statements like this:
INSERT INTO foo (auto,text)
VALUES(NULL,'text'); # generate ID by inserting NULL
INSERT INTO foo2 (id,text)
VALUES(LAST_INSERT_ID(),'text'); # use ID in second table
...found here:
http://www.mysql.com/doc/en/Getting_unique_ID.html
It works even without inserting the NULL value for some reason ;)
The following is great for monitoring:
$new_id = mysql_insert_id();
print "New id: $new_id\n";
Hope it helps you all, cheers.