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()?

Do you know if this is true only in the same connection context only? 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 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
>
> -----------------------------------------------
> Excellence in internet and open source software
> -----------------------------------------------
> Sunmaia
> www.sunmaia.net
> tel. 0121-242-1473
> -----------------------------------------------
>
> -----Original Message-----
> From: Alan McDonald [mailto:[EMAIL PROTECTED]]
> Sent: 16 October 2002 13:45
> To: [EMAIL PROTECTED]
> Subject: Inserting Master and Details records
>
>
> 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 be
> quickly returned with the newly created primary key, so that I might then
> insert the detail records with this primary key as their foreign key, does
> not seem very reliable to me (as suggested a few days ago).
>
> There must be a more reliable way to do this under heavy traffic.
> I'm afraid
> I'm used to being able to grab a generator ID and using that
> (guaranteed to
> be unique) for both the primary key of the master and the foreign
> key of the
> detail records. Surely there is a good method for use with MySQL....?
>
> Alan McDonald
> http://www.meta.com.au
>
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
>



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to