1

I have some code where variable $query is supposed to hold different PDOStatement objects, one replaced by another:

$query = $conn->prepare("select * from ... ");
$query->execute();
while ($tmp=$query->fetch(PDO::FETCH_ASSOC)) {
   ...;
}

//unset($query);
$query = $conn->query("select * from ... ");
while ($tmp=$query->fetch(PDO::FETCH_ASSOC)) {
    ....;
}  

With such code I get "SQLSTATE[HY000]: General error: 2050" from PDO on the line with the last fetch. But if I uncomment line with "unset" - it starts working correctly.

Any idea of what could it be?

PS Without using unset, it also works with PDO::ATTR_EMULATE_PREPARES = true

UPD Here is error code description from MySQL site:

Error: 2050 (CR_FETCH_CANCELED) Message: Row retrieval was canceled by mysql_stmt_close() call

user3714601
  • 1,156
  • 9
  • 27

1 Answers1

0

in some php versions error 2050 happen because you must empty the var that holds the object with the result of the query see https://stackoverflow.com/a/36631355/2613863

in Matt Cavanagh commet

yehonatan yehezkel
  • 1,116
  • 18
  • 28