mysql_insert_id in a Master Slave setup

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
girish.kc
Forum Newbie
Posts: 1
Joined: Tue Aug 10, 2010 1:39 am

mysql_insert_id in a Master Slave setup

Post by girish.kc »

Hi, I am planning to use a Master Slave setup in MySQL database. My concern is can I use the "mysql_insert_id()" function to get the recently inserted ID? Does it uses the "Select" query to get the latest inserted ID?
In that case my query may fail because, the insert query will be fired at master DB, but the select to slave DB. And there may be some delay in the replication.

Need help ..
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: mysql_insert_id in a Master Slave setup

Post by Gargoyle »

yes, it will work if you call mysql_insert_id() right after execution of the statement and if you use the same connection resource because the id is maintained for each single connection.
Post Reply