[ACCEPTED]-Fatal error: Call to undefined method PDO::close()-pdo
A PDO connection is closed by destroying its object:
The connection 9 remains active for the lifetime of that 8 PDO object. To close the connection, you 7 need to destroy the object by ensuring that 6 all remaining references to it are deleted--you 5 do this by assigning NULL to the variable 4 that holds the object. If you don't do this 3 explicitly, PHP will automatically close 2 the connection when your script ends.
$this->db = null;
should 1 work.
PDO doesn't have an explicit "close" function. You 2 can simply do
$this->db = null
to destroy the object, which 1 will automatically clean up the connections.
You close it by putting the handle to
From 1 php.net:
<?php $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); // use the connection here // and now we're done; close it $dbh = null; ?>
Setting the PDO variable to null closes 12 the connection and frees all related memory.
An 11 alternative to is to use closeCursor to 10 close the connection with the server but 9 leave the PDO Object around.
"closeCursor frees 8 up the connection to the server so that 7 other SQL statements may be issued, but 6 leaves the statement in a state that enables 5 it to be executed again."
That means 4 you can continue to run fetch() et al, even 3 though the connection has been freed.
Again, not 2 the same as mysql_close(), but nonetheless 1 incredibly useful.
PDO doesn't have a close method. To destroy 3 the connection the PDO object represents, destroy 2 all references to the object itself with 1 unset().
PDO hasnt close method. i think you can 2 try to unset $this->db, this disconnect 1 automatically
More Related questions