I have a code that works perfectly on the local server wampserver, it is a query interspersing the results the problem is that when I finish the site and host 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 the error is this:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE [HY000]: General error: 2014 Can not 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?