Reputation: 395
I was wondering if there's any method from the mysqli class for free memory after a get_result()
, I saw that people uses closeCursor()
method, but compiler says:
Call to undefined method mysqli_stmt::closeCursor()
and I call it through my prepared statement object like this $Statement->closeCursor();
I saw that closeCursor method closes the connection to the database too, so does it means that if I want to make another query I need to re-instantiate the mysqli class again? if so then, is there any other way I can do the same but leaving an opened connection? I'm only interested in free all the variables that result_sets leaves and start another query normally, thank's!
By the way, I'm doing this for a custom mysql backup system I'm just making, cheers! - Edgar.
Upvotes: 0
Views: 2844
Reputation: 5896
closeCursor()
is not a mysqli statement method.
What you are looking for is free_result and free
Upvotes: 3
Reputation: 9472
I could find an alternative to closeCursor ,using which you can free results , with out closing connection . ( this snippet is posted at manual in the comment section )
<?php
/**
* @param PDOStatement $oStm
*/
public static function closeCursor($oStm) {
do $oStm->fetchAll();
while ($oStm->nextRowSet());
}
?>
from PHP manual PDOStatement::closeCursor
As per the manual there
PDOStatement::closeCursor() is implemented either as an optional driver specific method (allowing for maximum efficiency), or as the generic PDO fallback if no driver specific function is installed. The PDO generic fallback is semantically the same as writing the following code in your PHP script:
<?php
do {
while ($stmt->fetch())
;
if (!$stmt->nextRowset())
break;
} while (true);
?>
Hope this helps
Upvotes: 1