Mysql无缓冲查询仍然失败

时间:2015-05-07 09:48:27

标签: php mysql pdo

我的PHP代码中出现以下错误:

PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement:fetchAll(). Alternatively if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

这些是我正在运行的查询,最终以此错误终止:

$db->exec("CREATE TEMPORARY TABLE {$dp}docs_tally (tally INT(11),date_clicked INT(11),accountID INT (11))");

$tally = $db->prepare(" SET @sum1 = 0;
                        INSERT INTO {$dp}docs_tally
                        SELECT (@sum1 := @sum1 + 1) as tally, date_clicked, accountID
                        FROM (
                            SELECT date_clicked,accountID
                            FROM `repository` drep
                            JOIN `clicks_or_downloads` dclick ON dclick.documentID = drep.ID
                            WHERE accountID = ?
                            ORDER BY dclick.ID ASC
                        ) vtable
                        GROUP BY date_clicked");

foreach ($accs_data as $row){
        $tally->execute(array($row['accountID']));
}

我尝试将数组(PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY => true)添加到此处给出的prepare语句(http://php.net/manual/en/ref.pdo-mysql.php)。我也设定了:

$this->db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);

当我在这个参数上运行getAttribute时它确实返回true,所以问题是为什么当这个属性打开时我仍然会收到错误告诉我打开它吗?

0 个答案:

没有答案