PDOStatement :: nextRowSet()在Windows上的MySQL 5.6.16中损坏 [英] PDOStatement::nextRowSet() is broken in MySQL 5.6.16 on Windows

查看:38
本文介绍了PDOStatement :: nextRowSet()在Windows上的MySQL 5.6.16中损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题,没有被接受的答案提出我在Windows上以修改后的形式在MySQL版本5.6.16上遇到的MySQL灾难性问题.

This question without an accepted answer raises a catastrophic problem with MySQL that I am experiencing on MySQL version 5.6.16 on Windows in a modified form.

该问题很容易重现:我在此添加了该问题(从上述链接的问题复制而来,但有适用于我的代码的更改)

The problem is easily reproducible: I include it here (copied from the above-linked question, but with changes applicable to my code):

$pdo = /* connection stuff here */
$sql = "call test();"; // call stored procedure - see below
$statement = $connection->query($sql);
do {
    $rowset = $statement->fetchAll(PDO::FETCH_ASSOC);
    if($rowset) {
        // Do stuff with $rowset
    }
} while($statement->nextRowset());

这是存储过程test的定义:

DELIMITER $$
DROP PROCEDURE IF EXISTS `test`$$
CREATE PROCEDURE `test`()
BEGIN    
    SELECT 1; SELECT 2; SELECT 3; SELECT 4;
END$$
DELIMITER ;

我的代码和上面链接的代码之间的唯一区别是,我将SQL查询打包到存储过程中.

The only difference between my code, and the above-linked code, is that I pack the SQL query into a stored procedure.

就我而言,while语句返回true的次数是四次,而不是三倍(应该只是三倍).第四次之后,fetchAll(...)引发SQLSTATE[HY000]: General error错误.

In my case, the while statement returns true four times, rather than three times (it should be just three times). After the fourth time, fetchAll(...) throws a SQLSTATE[HY000]: General error error.

不幸的是,这个问题是灾难性的.除了使用nextRowSet()函数外,PDO没有其他方法可以迭代到随后的行集.因此,为了解决此问题,我可能会还原到MySQL的早期版本.

Unfortunately, this problem is catastrophic. There is no other way with PDO to iterate to following rowsets other than using the nextRowSet() function. Therefore, I may revert to a previous version of MySQL in order to work around this issue.

我找到了两个似乎表明此问题的链接,在此处列出: https://bugs.php.net/bug.php?id=67130 http://permalink.gmane.org/gmane.comp.php.devel/81518

I have found two links that seem to indicate this issue, listed here: https://bugs.php.net/bug.php?id=67130 and http://permalink.gmane.org/gmane.comp.php.devel/81518

我希望能确认这确实是Windows上MySQL 5.6.16版本的错误.更甚者,我希望能找到一种解决方法.谢谢.

I would appreciate a confirmation that this is, indeed, a bug with version 5.6.16 of MySQL on Windows. Even more, I would appreciate a workaround. Thanks.

推荐答案

我对PDO :: nextRowset()遇到了同样的问题,因为即使没有可用的行集,它也会返回true,因此在调用fetchAll()时会引发HY000例外. (在PHP 5.5.12 Windows,Mysql 5.5.17 linux上进行了测试)

I had same problem with PDO::nextRowset(), as it returns true even there are no more rowsets available, therefore when calling fetchAll(), it raises exception HY000. (tested on PHP 5.5.12 windows, Mysql 5.5.17 linux)

此问题的解决方法是在获取行集之前使用方法PDO :: columnCount()检查列数.如果它不为零,则您有一个有效的行集,因此可以调用PDO :: fetchAll().

A workaround for this problem is to check number of columns with method PDO::columnCount() before fetching rowset. If it is non-zero, you have a valid rowset, and thus you could call PDO::fetchAll().

即使PDO :: nextRowset()报告为true,columnCount()也会报告移至下一个行集之前的列数.

Even if PDO::nextRowset() reports true, columnCount() will report number of columns before moving to next rowset.

示例:

while ($objQuery->columnCount()) {
    $tab[] = $objQuery->fetchAll(\PDO::FETCH_ASSOC);
    $objQuery->nextRowset();
}

这篇关于PDOStatement :: nextRowSet()在Windows上的MySQL 5.6.16中损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆