###Transaction
function transaction($sqlQueue)
{
//$this->connection();
if(count($sqlQueue)>0)
{
/*
* Manual says:
* If you do not fetch all of the data in a result set before issuing your next call to PDO::query(), your call may fail. Call PDOStatement::closeCursor() to release the database resources associated with the PDOStatement object before issuing your next call to PDO::query().
* */
$this->result->closeCursor();
if($this->charset !== NULL)
{
$this->db->exec("SET NAMES ".$this->charset);
}else{
$this->db->exec("SET NAMES utf8");
}
try
{
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$this->db->beginTransaction();
foreach ($sqlQueue as $sql)
{
$this->db->exec($sql);
}
$this->db->commit();
return true;
} catch (Exception $e) {
$this->logWriter->writeLog("事务处理出错:".$e->getMessage()."\nSQL语句:".Utils::arrToString($sqlQueue));
$this->db->rollBack();
return false;
}
}else{
return false;
}
}
转自:http://www.flashj.cn/wp/pdo-transaction-err-in-php.html