On Mon, Dec 15, 2003 at 01:42:30PM -0600, Paul Fine wrote:
> Thanks (to all who replied)
> 
> If I lock the table however, if another user is trying to insert (via php
> page) another record they will get an error right and I will need to make a
> wait+retry script?


_if_ you lock the other threads will wait. But you really do not need to
lock the whole table. last_insert_id() works (just as the corresponding PHP
function) on a _per connection_ base. See the manual @
http://mysql.com/doc/en/Miscellaneous_functions.html -> LAST_INSERT_ID


good luck,

Harmen




> 
> Thanks!
> 
> -----Original Message-----
> From: Tobias Asplund [mailto:[EMAIL PROTECTED] 
> Sent: Monday, December 15, 2003 12:56 PM
> To: Paul Fine
> Cc: [EMAIL PROTECTED]
> Subject: Re: Best way to get value of autoincriment after inserting NULL?
> 
> On Mon, 15 Dec 2003, Paul Fine wrote:
> 
> > If I have a table like with a column being the PK for the table and being
> an
> > Auto Increment value, what is the best way to return this value to my
> > script?
> 
> If you insert a row LAST_INSERT_ID() will return the primary key value in
> this setup.
> 
> The other way is if you're not inserting a record, but just want to know
> the next value that will be used.
> SHOW TABLE STATUS LIKE '<tablename>';
> 
> 
> > It is possible that additional rows may have been added during the
> > small wait.
> 
> It is possible another value is inserted in between the query for the next
> number and an insert afterwards.
> To stop this from happening you can place a read-lock on the table, this
> won't allow any other processes to insert rows until you release the lock.
> 
> LOCK TABLE <tablename> READ;
> Get Auto-increment value
> 
> Do your stuff...
> 
> UNLOCK TABLES;
> 

-- 
                                The Moon is Waning Gibbous (60% of Full)
                                   tty.nl - ericsson.2dehands.nl: 109313

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to