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