Error in PDO query

Asked

Viewed 1,187 times

5

I am creating a registration page where I have several tabs, as the structure below:

<div> Aba 1 </div>
<div> Aba 2 </div>
<div> Aba 3 </div>
<div> Aba 4 </div> e assim vai...

Within each tab I have an sql query using PDO, only when I arrive at the tab 4 appears the following error message:

Array ( [0] => 00000 [1] => 2014 [2] => Cannot execute queries while other Unbuffered queries are active. Consider using Pdostatement::fetchAll(). Alternatively, if your code is only Ever going to run Against mysql, you may enable query buffering by Setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. )

I already activated and deactivated the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY but nothing solves...

* My Consultation *

<tbody>
    <?php
        $sql5 = "CALL sp_FornecedorAnalitico_Selecionar(:codigoFornecedor, :tipo)";
        $stmt5 = $conexao_oo->conn->prepare($sql5);
        $stmt5->bindValue(":codigoFornecedor", $_GET['codForn']);
        $stmt5->bindValue(":tipo", 5);
        $stmt5->execute();
        $dadosFornecedor5 = $stmt5->fetchAll(PDO::FETCH_OBJ);
        print_r($stmt5->errorInfo());
        foreach ($dadosFornecedor5 as $pedido) {
            echo "<tr>";
                echo "<td>".$pedido->codSol."</td>";
                echo "<td>".$pedido->numPedido."</td>";
                echo "<td>".$pedido->solicitante."</td>";
                echo "<td>".$pedido->empresa."</td>";
                echo "<td>".$pedido->setor."</td>";
                echo "<td>".$pedido->tipo."</td>";
                echo "<td>".$pedido->prevEntrega."</td>";
                echo "<td></td>";
                echo "<td>".$pedido->condicao."</td>";
                echo "<td>".$pedido->status_sc."</td>";
                echo "<td>".$pedido->valor_total."</td>";
                echo "<td><a target='_blank' title='Visualizar Itens da Solicitação' href='visualizar_sc.php?cod_solicitacao=".$valor->codScompra."'><img src='images/icons/search.png'></a></td>";
                echo "</tr>";
        }
    ?>
</tbody>
  • Could put part of the source code.

  • 1

    place the part where you request PDO not only html please

  • I edited the question...I put there how I am doing the PDO request

  • Before this code has four more queries? , this reply from Soen suggests that you each 'query' after the execute() thus: $stmt5->closeCursor();

  • @rray Valew... it worked !!

  • The closeCursor() you called after the execute() or of fetchAll()?

  • after fetch(), there is a difference ????

  • I tested after execute() and did not come the query result, only returned the lines when I called after fetch/fetchAll, in my test I did not use stored Procedure.

Show 3 more comments

1 answer

3


Based on that reply from Soen and in the manual, when you have to perform multiple queries in sequence close the course to release the server resource using closeCursor() after fetchAll()

    $stmt5->execute();
    $dadosFornecedor5 = $stmt5->fetchAll(PDO::FETCH_OBJ);
    $stmt5->closeCursor();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.