php - What do I need to do, if anything, to ensure $mdb2->lastInsertID() returns the auto-increment value for that connection? -
i've made switch sql server mysql, , can't find solid enough answer question anywhere:
i'm using php, mysql, , innodb table engine on tables need lock. standard series of 3 statements:
- insert table a
- $id = $mdb2->lastinsertid()
- insert table b (name, fk) values ('foo', $id)
what steps need take make sure $id has value of insert step 1? fine way is? need in transaction? need add other queries lock , release tables?
thanks guys.
you should/could, don't need anything: information-functions , function_last-insert-id
the id generated maintained in server on per-connection basis. means value returned function given client first auto_increment value generated recent statement affecting auto_increment column client. value cannot affected other clients, if generate auto_increment values of own. behavior ensures each client can retrieve own id without concern activity of other clients, , without need locks or transactions.
Comments
Post a Comment