当我使用相同的连接语句(使用PDO)执行第二个存储过程时,得到以下错误。
=============================================== ==
SQLSTATE [HY000]: 常规错误:2014在其他未缓冲的查询处于活动状态时无法执行查询。考虑使用PDOStatement :: fetchAll()。 或者,如果您的代码只是针对mysql运行,您可以通过设置启用查询缓冲 PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY属性。
=============================================== ======
这是我在drupal中的代码
$conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$statement = $conn->prepare("CALL Odd_Get_Sport()");
$exec_result = $statement->execute();
while ($row = $statement->fetchObject()) {
print_r($row);
}
$statement ->closeCursor();
$statement1 = $conn->prepare("CALL Odd_Get_Sport()");
$exec_result1 = $statement1->execute();
while ($row1 = $statement1->fetchObject()) {
print_r($row1);
}
帮助我。
答案 0 :(得分:2)
这是PDO的一个不好的功能,没有很好的记录。当语句执行存储过程时,closeCursor方法不起作用。您需要使用nextRowSet方法。这是我使用的
while($sth->nextRowSet())
{
$sth->fetchAll();
}
$sth->closeCursor();
答案 1 :(得分:-1)
只需在每次准备前将其设置为 null
result
product 04-01 04-02 04-03 04-05 04-06
cycle 12 48 75 68 195
bike 42 30 12 376 15
bycyle 111 46 36 16 475