我有这个代码:
$this->db->beginTransaction();
$query = 'INSERT INTO `table1` VALUES (NULL,:a,:b,NULL,NOW())';
$sth = $this->db->prepare($query);
foreach ($values as $k => $v) {
$sth->bindParam(':' . $k, $v, PDO::PARAM_INT);
}
$this->executeQueryRollbackOnException($sth, 'Message_1');
$resetId = $this->db->lastInsertId();
$query = 'UPDATE `table2` SET c=:c,d=:d WHERE reset_id IS NULL';
$sth = $this->db->prepare($query);
foreach ($values2 as $k => $v) {
$sth->bindParam(':' . $k, $v, PDO::PARAM_INT);
}
$this->executeQueryRollbackOnException($sth, 'Message_2');
Zend_Debug::dump($sth->rowCount(), 'Affected'); // This is 0
// Commit
$this->db->commit();
...
private function executeQueryRollbackOnException($sth, $message) {
try {
$sth->execute();
} catch (Exception $e) {
$this->logSQLError($e);
$this->db->rollBack();
throw new Exception($message);
}
}
第一个查询已执行,但第二个未执行。没有产生mysql错误。有任何想法吗 ?