Hi
insert_id returns the key value. I use php, and the mysql_insert_id is the
last insert_id on that connection, so even if other processes have added new
records in the time the script runs the insert_id is the correct one.
You can then use that as the key in the detail records.
HTH
Peter
* Alan McDonald
My task is to insert a new master record and several detail records within
the one transaction.
There is a foreign key on the detail table set to the unique key (autoinc)
field of the master table.
Inserting a master record, even with a special field value so
that it can
? Or
does insert_id() return another connections last insert?
Alan
-Original Message-
From: Peter Lovatt [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 17 October 2002 0:59
To: Alan McDonald; [EMAIL PROTECTED]
Subject: RE: Inserting Master and Details records
Hi
insert_id returns
Sorry your second link makes that claim a little clearer - it's on a
per-connection basis
Alan
-Original Message-
From: Roger Baklund [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 16 October 2002 23:58
To: [EMAIL PROTECTED]
Cc: Alan McDonald
Subject: Re: Inserting Master and Details
Alan McDonald wrote:
Do you know if this is true only in the same connection context only? Or
does insert_id() return another connections last insert?
I find it easiest to use MySQL's variables:
INSERT INTO Master ...
SELECT @MasterID:=last_insert_id();
INSERT INTO Detail1 (MasterID, Data)
Alan,
Wednesday, October 16, 2002, 5:07:05 PM, you wrote:
AM Thanks you - I looked up Insert_ID() in the manual...
AM Page 171-172
AM If I insert into person but before I insert into short, someone else inserts
AM into person, surely my inserts into shirt will have their last Insert_ID()?
sql,query
At 0:07 +1000 10/17/02, Alan McDonald wrote:
Peter,
Thanks you - I looked up Insert_ID() in the manual...
Page 171-172
If I insert into person but before I insert into short, someone else inserts
into person, surely my inserts into shirt will have their last Insert_ID()?
Surely