$db = Zend_Db_Table::getDefaultAdapter();
$db->beginTransaction();
$row = array('superwords_description' => $label);
$db->insert('fc_superwords', $row);
printDebug($db->lastInsertId('fc_superwords', 'superwords_id'));
$db->rollBack();
printDebug($db->lastInsertId('fc_superwords', 'superwords_id'));
This returns output like:
ImportController:47: 36
ImportController:49: 0
I am just testing writing some data and then rolling back the changes. And
it works, sort of. The data isn't saved to the database. And yet, my
DatabaseObject thinks that it's AUTO_INCREMENT id is increasing. If I
reload the page 10 times, the lastInsertId is returned as 10 consecutive
numbers. If I commit on the eleventh reload instead, the PRIMARY_KEY value
includes all the failed attempts.
In other words, if I start at 36 and reload 3 times, the output looks like
this:
ImportController:47: 39
ImportController:49: 0
And if I save on the next reload, the primary key will be saved as 40, even
though no data was actually saved to records number 37, 38, or 39.
This seems wrong and I am wondering if anything can be done about it? Has
anyone else seen this behavior?
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Transactions-and-auto-increment-tp2309975p2309975.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论