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)
– buback
I tried to change following the most unsuccessful error response. Same thing happens.
– wildson
you tried to run SQL directly on your DBMS?
– buback
yes executed and worked perfectly
– wildson
Before this code has any other query? could put part of it in the question.
– rray
managed to solve?
– rray
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
– wildson