您的位置:首页 > 其它

PDO处理事务部分的报错 :Uncaught exception 'PDOException' with message There is no active transaction

2014-05-26 10:42 821 查看
###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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐