Re: How to retrieve record-id after 'insert into'?

2001-05-22 Thread Siomara Pantarotto

In order to retrieve the id you inserted and not someones's id that was 
inserted a bit after yours, I guess you should lock the table before your 
insert statement, do the insert, retrieve the id just inserted, and then 
unlock the table so others can operate with the table again.

This is my guess...

Anybody have another way???

Siomara

From: Peter Pentchev [EMAIL PROTECTED]
To: Viktor van den Berg [EMAIL PROTECTED]
CC: [EMAIL PROTECTED]
Subject: Re: How to retrieve record-id after 'insert into'?
Date: Mon, 21 May 2001 17:21:44 +0300

On Mon, May 21, 2001 at 03:58:10PM +0200, Viktor van den Berg wrote:
 
  Hi!
 
  I like to know how to retrieve the record id after an insert into 
query.
  I have the table user containing two columns: UID (auto_increment) and
  USERNAME. After I have added a new user (using insert into user (uid)
  etc.) I like to know the UID of the new record.
 
  I can set the record pointer to the last record, but if anybody else 
also
  inserts a record at the same time, I think this will give a problem.
 
  Can anybody give me a suggestion?

Look at the MySQL manual.  Reference  INSERT, look for mentioning of
AUTO_INCREMENT fields, and specifically, for a reference to the
LAST_INSERT_ID() function.

Simple, isn't it? :)  All referenced in the manual, if you take the time
to check what the manual has to say about 'INSERT'.. :)

G'luck,
Peter

--
This inert sentence is my body, but my soul is alive, dancing in the sparks 
of your brain.

-
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


_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


-
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




Re: How to retrieve record-id after 'insert into'?

2001-05-22 Thread Peter Pentchev

Did you take a look at the LAST_INSERT_ID() function I mentioned?

G'luck,
Peter

-- 
This sentence no verb.

On Tue, May 22, 2001 at 01:53:24PM -0300, Siomara Pantarotto wrote:
 In order to retrieve the id you inserted and not someones's id that was 
 inserted a bit after yours, I guess you should lock the table before your 
 insert statement, do the insert, retrieve the id just inserted, and then 
 unlock the table so others can operate with the table again.
 
 This is my guess...
 
 Anybody have another way???
 
 Siomara
 
 From: Peter Pentchev [EMAIL PROTECTED]
 To: Viktor van den Berg [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]
 Subject: Re: How to retrieve record-id after 'insert into'?
 Date: Mon, 21 May 2001 17:21:44 +0300
 
 On Mon, May 21, 2001 at 03:58:10PM +0200, Viktor van den Berg wrote:
  
   Hi!
  
   I like to know how to retrieve the record id after an insert into 
 query.
   I have the table user containing two columns: UID (auto_increment) and
   USERNAME. After I have added a new user (using insert into user (uid)
   etc.) I like to know the UID of the new record.
  
   I can set the record pointer to the last record, but if anybody else 
 also
   inserts a record at the same time, I think this will give a problem.
  
   Can anybody give me a suggestion?
 
 Look at the MySQL manual.  Reference  INSERT, look for mentioning of
 AUTO_INCREMENT fields, and specifically, for a reference to the
 LAST_INSERT_ID() function.
 
 Simple, isn't it? :)  All referenced in the manual, if you take the time
 to check what the manual has to say about 'INSERT'.. :)

-
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




How to retrieve record-id after 'insert into'?

2001-05-21 Thread Viktor van den Berg


Hi!

I like to know how to retrieve the record id after an insert into query. 
I have the table user containing two columns: UID (auto_increment) and 
USERNAME. After I have added a new user (using insert into user (uid) 
etc.) I like to know the UID of the new record.

I can set the record pointer to the last record, but if anybody else also 
inserts a record at the same time, I think this will give a problem.

Can anybody give me a suggestion?

thanks in advance,
Viktor v/d Berg


-
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