--- BD <[EMAIL PROTECTED]> wrote:
> Son,
> 
> At 09:48 PM 4/7/2002, you wrote:
> >mysql> desc threads;
>
>+-------------+--------------+------+-----+---------+----------------+
> >| Field       | Type         | Null | Key | Default | Extra         
> |
>
>+-------------+--------------+------+-----+---------+----------------+
> >| thread_ID   | int(11)      |      | PRI | NULL    | auto_increment
> |
> >| subject     | varchar(255) | YES  |     | NULL    |               
> |
> >| author      | varchar(30)  | YES  |     | NULL    |               
> |
> >| last_by     | varchar(30)  | YES  |     | NULL    |               
> |
> >| views       | int(11)      |      |     | 0       |               
> |
> >| date_posted | datetime     | YES  |     | NULL    |               
> |
>
>+-------------+--------------+------+-----+---------+----------------+
> >6 rows in set (0.00 sec)
> >
> >   $SQL_insert_thread = "INSERT into threads ";
> >   $SQL_insert_thread .= "(subject, author, last_by, views, ";
> >   $SQL_insert_thread .= "date_posted) " values ";
> >   $SQL_insert_thread .= "(\'some_subject\', \'test_username\',
> >   $SQL_insert_thread .= "\'test_username\', 1, now())";
> >
> >   In the table threads above, I do have a field: "thread_ID" with
> >auto_increment value. My question is can I obtain the value
> thread_ID
> >while I do the insert statement just by 1 mySQL statement?  If yes,
> >please can somebody give me a sample code?
> 
> execute the MySQL query:  select last_insert_id();

1st: select last_insert_id() doesn't work

2nd: It's not the answer I am looking for ... Because of the race
condition if two users access the that script at the same time... I
will have when I leave the INSERT statement !!! 

Here is what I mean: think about this situation:

USER 1  ===> INSERT
             STOP <== due to process scheduling

USER 2  ===> INSERT
             SELECT last_insert_id();

USER 1  ===> SELECT last_insert_id();

It's the race condition, I am talking about.

> and retrieve the returned value
> 
> or
> 

> $last_thread_id = mysql_insert_id();
> This function will not work properly if the auto-incrementing column
> is 
> BigInt, because PHP does not have a BigInt equivalent. Int or smaller
> works 
> fine.
> 
> Brent
> 
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.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
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.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

Reply via email to