mdb2 help
| From: | Jordan Spivack | Date: | Wed, 03 Aug 2011 23:17:54 +0000 |
| Subject: | mdb2 help | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-31187@lists.php.net to get a copy of this message | ||
Hey everyone, sorry this is a repost from Stack Overflow but I still
desperately need a definitive answer.
I'm currently using PHP, the mdb2 package, MySQL, and the InnoDB table
engine for database development. I want to be 100% sure that when I insert
into a table and then use lastInsertID(), it will contain the correct auto
increment value for that table regardless of whether or not another user is
executing the same query. Basically, I need to lock the tables.
So for a standard series of 3 statements:
1. Insert into table A
2. $id = $mdb2->lastInsertID()
3. Insert into table B (name, fk) VALUES ('foo', $id)
what steps do I need to take to make sure $id has the value of the insert
from step 1? Is it fine the way it is? Does everything need to be in a
transaction? Do I need to add other queries to lock and release the tables?
Thanks guys.
--
Jordan Spivack
Lead Web Architect - Athens Social Media
cell: 706.207.4974
http://www.athenssocialmedia.com