note 14566 modified in function.mysql-insert-id by didou
| From: | didou@php.net | Date: | Sat, 17 May 2003 21:08:07 +0000 |
| Subject: | note 14566 modified in function.mysql-insert-id by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48269@lists.php.net to get a copy of this message | ||
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.
--was--
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/G/e/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.
http://www.php.net/manual/en/function.mysql-insert-id.php