php - 一般错误 2014 在 closeCursor() 之后仍然发生

标签 php mysql pdo

我通读了其他答案,大多数答案都是通过添加 $sth->closeCursor(); 解决的。 我多次调用 sprocs,但每次调用时仍然出现错误。

这是我的代码:

 <?php
 $sql = "CALL get_salesquote_lineitems(:salesquoteguid);";
 $array = array('salesquoteguid' => $salesquoteguid);
 $sth = $dbh->prepare($sql);
 if ($sth->execute($array)) {
     $lineItems = $sth->fetchAll(PDO::FETCH_ASSOC);
     $sth->closeCursor();
 }

 $sql = "CALL get_salesquote_totals(:salesquoteguid);";
 $array = array('salesquoteguid' => $salesquoteguid);
 $sth = $dbh->prepare($sql);
 if ($sth->execute($array)) {
    $totalData = $sth->fetchAll(PDO::FETCH_ASSOC);
    $sth->closeCursor();
 }

 $sql = "CALL get_salesquote_data(:salesquoteguid);";
 $array = array('salesquoteguid' => $salesquoteguid);
 $sth = $dbh->prepare($sql);
 if ($sth->execute($array)) {
    $quoteData = $sth->fetchAll(PDO::FETCH_ASSOC);
    $sth->closeCursor();
 }

 $sql = "CALL get_salesquote_warranty_rows(:salesquoteguid);";
 $array = array('salesquoteguid' => $salesquoteguid);
 $sth = $dbh->prepare($sql);
 if ($sth->execute($array)) {
    $warrantyRows = $sth->fetchAll(PDO::FETCH_ASSOC);
    $sth->closeCursor();
 }

我也试过:

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

还有什么需要帮忙的吗? 谢谢

最佳答案

将 closeCursor() 移到 if 之外,以便始终执行它。

$sql = "CALL get_salesquote_totals(:salesquoteguid);";
$array = array('salesquoteguid' => $salesquoteguid);
$sth = $dbh->prepare($sql);
if ($sth->execute($array)) {
   &nbsp;&nbsp;$totalData = $sth->fetchAll(PDO::FETCH_ASSOC);
}
$sth->closeCursor();

关于php - 一般错误 2014 在 closeCursor() 之后仍然发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19544177/

相关文章:

php - Laravel 多个数据库连接不起作用

php - 预期响应代码 250 但得到代码 "535",消息“535-5.7.8 用户名和密码不被接受

mysql - 聚合重复与嵌套查询

php - PDO::PARAM_* 与强制转换

php - 出现一般错误 : 4004 General SQL Server error:

php - MariaDB - 发票编号 - 每年返回0

php - 如何反转一组逗号分隔的字符串并在 PHP 中以原始顺序返回它们?

mysql - SQL BUG 在写 != 时不接受 null

mysql - sql LEFT JOIN查询的使用方法

php - 如何使用多个准备语句(mysql、PDO)?