4

我阅读了其他答案,大多数都通过添加 $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);

请问还有什么帮助吗?谢谢

4

1 回答 1

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();
于 2013-11-08T13:10:21.087 回答