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.

Recommended Answers

All 4 Replies

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 ...

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>

Okay..
thanks..
So, I will try to use it..

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.