Forum Moderators: open
Thank you very much for your help.
[edited by: Woz at 10:45 am (utc) on Nov. 17, 2005]
[edit reason] No email addresses please, see TOS. [/edit]
INSERT INTO table1 (pri_field, field2, field3, field4) VALUES (null, 'some value', 'other value', null);
INSERT INTO table2 (sec_key, field, otherfield) VALUES ((SELECT max(pri_field) FROM table1 WHERE field2 = 'some value' AND field3 = 'other value' AND field4 is null), 'bleh', 'bleh bleh');
And I'm sure someone else has a better suggestion too :)
you can use this as the guys said :
INSERT INTO tbl (auto,text) VALUES(NULL,'text');
INSERT INTO tbl2 (id,text) VALUES(LAST_INSERT_ID(),'text');
and you can check this link :
[dev.mysql.com...]
Parameters
link_identifier
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.
However its even more reliable then that might imply:
Here's the relevant quote from the manual on LAST_INSERT_ID() which is located here: [dev.mysql.com...]
"The last ID that was generated is maintained in the server on a per-connection basis. This means the value the function returns to a given client is the most recent AUTO_INCREMENT value generated by that client. The value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that you can retrieve your own ID without concern for the activity of other clients, and without the need for locks or transactions."