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

来源:互联网 发布:恐怖悬疑电影 知乎 编辑:程序博客网 时间:2024/05/20 01:08
    ###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


0 0
原创粉丝点击