Reputation: 465
When I have a loop like this:
foreach(...) {
$r1 = $zend_db->fetchRow("SELECT ... ");
$zend_table->insert($data_array, $where);
}
... running a few thousand times. Is it possible, that $r1
doesn't contain a record inserted in the previous loop?
At http://dev.mysql.com/doc/refman/5.1/en/query-cache.html they write "The query cache does not return stale data. When tables are modified, any relevant entries in the query cache are flushed." But maybe ZEND does some unexpected caching for SELECT or INSERT?
Do I need to use transactions to solve this?
I had an issue with double records and there is no other explanation where they came from. But I can't reproduce it, cause it happened two months ago, importing csv-data that no longer exists.
Upvotes: 4
Views: 287
Reputation: 8186
As said by drew010 in comment Zend_Db does no caching unless you implement it yourself . For next time to be sure about the problem try something like this
try {
foreach(...) {
$r1 = $zend_db->fetchRow("SELECT ... ");
$zend_table->insert($data_array, $where);
}
} catch(Zend_Db_Exception $e)
{
$logger->log($e->getMessage(),Zend_Log::CRIT); //$logger is instance of Zend_Log
}
Upvotes: 1