DNB5brims
DNB5brims

Reputation: 30588

Alternative for mysql_insert_id in mysql?

I google the mysql_insert_id, about the thread safe concern... ...I am worrying about I only have a one MySQL user to connect DB, so, I think mysql_insert_id is not very safe for my application. Is there any "safer" method for returning last insert id from MySQL? thank you.

Upvotes: 0

Views: 1809

Answers (2)

Stephan B
Stephan B

Reputation: 3701

As long as no two threads share one database connection you should not get any wrong ids. mysql_insert_id is stored per connection, not per user.

Upvotes: 5

Vladislav Rastrusny
Vladislav Rastrusny

Reputation: 29985

There is no safer method and you don't need any. mysql_insert_id() in PHP or SELECT LAST_INSERT_ID() returns the last ID per your current connection, not per user account, so you are perfectly safe here.

Upvotes: 1

Related Questions