0

Hi all,
I'm still a newbie in programming world..
And I just realized that PHP has a function "mysql_insert_id()" to get the most recent id that generated by AUTO INCREMENT.

But, before I use it, I want to know
Is it safe to use it when many users insert data in the same page?
For example, there are many users register to a site at the same time.
Will there any conflict?
Or everything will be alrigth?

Thanks,

Sorry for my English.

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by phpbeginners
0

Yeah safe because when user request for each page than it comes from the server and execute on the client side so no problem in i t..You can use any time..No issue in it

Please search Server HTTP request ...

0

It is safe to use mysql_insert_id() in your program, because mysql creates different instances for different users, the inserted id will be depends on the server instance created by the mysql server.

Thanks & Regards
Sai Prem
<snipped>

Edited by nav33n: Fake signature snipped. Please use Control Panel -&gt; Edit signature to add signature to your profile.

0

I give you this just for more information using mysql_insert_id() according to the php manual :-)

Caution

mysql_insert_id() converts the return type of the native MySQL C API function mysql_insert_id() to a type of long (named int in PHP). If your AUTO_INCREMENT column has a column type of BIGINT, the value returned by mysql_insert_id() will be incorrect. Instead, use the internal MySQL SQL function LAST_INSERT_ID() in an SQL query.


Note: Because mysql_insert_id() acts on the last performed query, be sure to call mysql_insert_id() immediately after the query that generates the value.

Note: The value of the MySQL SQL function LAST_INSERT_ID() always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries.

Edited by phpbeginners: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.