closeCursor()之后仍然会发生一般错误2014

时间:2013-10-23 14:13:01

标签: php mysql pdo

我读了其他答案,大多数都是通过添加$ sth-> closeCursor()来解决的。 我有多次调用sprocs后仍然得到每个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);

还有什么进一步的帮助吗? 感谢

1 个答案:

答案 0 :(得分:0)

将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();