25

there is a mysql function in php called mysql_free_result(); I couln't find any similar function for PDO.

is there a pdo function to free the result of a database fetch or does the result set automatically get requested and freed when I call $stmt->fetch() data?

could someone explain me this difference between native mysql and pdo?

Timo Huovinen
  • 53,325
  • 33
  • 152
  • 143

2 Answers2

17

closest method is close cursor for PDO statements.

http://us.php.net/manual/en/pdostatement.closecursor.php

$stmt = $dbh->prepare('SELECT foo FROM bar');
$stmt->closeCursor();
Timo Huovinen
  • 53,325
  • 33
  • 152
  • 143
dqhendricks
  • 19,030
  • 11
  • 50
  • 83
  • 1
    so it's not necessary for pdo to flush large result sets? – Timo Huovinen May 22 '11 at 09:44
  • 1
    for some drivers it is necessary to close all result set before you can create another. – dqhendricks May 22 '11 at 16:38
  • 2
    Not *just* some drivers -- some *settings* provided by drivers require closing the result set before firing off another query, like turning off MySQL's [`PDO::MYSQL_ATTR_USE_BUFFERED_QUERY`](http://us2.php.net/manual/en/ref.pdo-mysql.php#pdo-mysql.constants). Thankfully you can call `closeCursor` and it will successfully do nothing when it doesn't need to take action. Otherwise simply unsetting the variable containing the statement handle will clean up. – Charles May 23 '11 at 18:36
4

You can set the object variable to null. The GC will destroy the PDO Statement instance, I guess.

Stijn Leenknegt
  • 1,317
  • 4
  • 12
  • 22