Uncaught Exception Pdoexception error with message 'SQLSTATE[HY000]: General error: 2014

Asked

Viewed 1,386 times

1

I have a code that works perfectly on the local wampserver server, it is a query interspersing the result the problem is that when finishing the site and hosting it I get an error.

The code is this:

$conn->exec('SET @orderA := 0; SET @orderB := 0;');
$q = $conn->prepare("
SELECT id, voz
FROM (
    SELECT id, voz
    ,IF(voz = 'voz-feminina', @orderA := @orderA + 1, IF(voz = 'voz-masculina', @orderB := @orderB + 1, null)) AS idx
    FROM musica
    WHERE audio = 'pop'
) AS a
ORDER BY idx, voz;
");
$q->execute();
while ($linha = $q->fetch(PDO::FETCH_ASSOC)) {
    echo $linha['voz'];
}

And that’s the mistake:

Fatal error: Uncaught Exception 'Pdoexception' with message 'SQLSTATE[HY000]: General error: 2014 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. ' in D: web localuser www new index.php:15 Stack trace: #0 D: web localuser www new index.php(15): Pdostatement->execute() #1 {main} thrown in D: web localuser www new index.php on line 15

What can it be?

  • The error itself suggests an edit: "Consider using fetchAll()". $line = $q->fetchAll(PDO::FETCH_ASSOC)

  • I tried to change following the most unsuccessful error response. Same thing happens.

  • you tried to run SQL directly on your DBMS?

  • yes executed and worked perfectly

  • Before this code has any other query? could put part of it in the question.

  • managed to solve?

  • 1

    Opa ok. I’m not sure if it was a solution, but I asked the provider to change the version of php to the last version and solved the problem. but this code does not work in the old version which is the 5.2.XX of php

Show 2 more comments

3 answers

1


Good person. Thank you all for your efforts. When I was developing this code in php on a local server I used the version of php 5.5.12 and it worked perfectly, my problems started when I uploaded the code to a hosting server with the version of php 5.2.xx then presented this problem. when I realized the difference of versions I asked for a migration to a server with version php 5.5.12 or higher, and fixed problem. I don’t know if this was really a solution or a gambiarra. but now it’s all running perfectly. Thanks to all the stackoverflow programmers, you’re 10.

0

Try it like this:

$conn->exec('SET @orderA := 0; SET @orderB := 0;');

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

$q = $conn->prepare("
SELECT id, voz
FROM (
    SELECT id, voz
    ,IF(voz = 'voz-feminina', @orderA := @orderA + 1, IF(voz = 'voz-masculina', @orderB := @orderB + 1, null)) AS idx
    FROM musica
    WHERE audio = 'pop'
) AS a
ORDER BY idx, voz;
");
$q->execute();

$resultados = new ArrayIterator($q->fetchAll(PDO::FETCH_OBJ));

foreach($resultados as $res) {
    echo $res->voz;
}
  • same error. when I take the first line shows the result more not intercalated

  • I saw something similar on github and was fixed by putting $Conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);

0

If you have an appointment before the exec(), close it before starting the next with closeCursor(), this is recommended in the case of multiple queries and in the use of fetch().

$stmt->closeCursor(); //fecha a consulta anterior
$conn->exec('SET @orderA := 0; SET @orderB := 0;');
  • Problem solved. code does not work in old php version.

  • @Wildson, creates an answer better describing the details of how to solve the problem.

Browser other questions tagged

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