Search code examples
phpdatabasepear

php pear db disconnect


do i need manually call disconnect() ?

for example

    <?php
    // Create a valid DB object named $db
    // at the beginning of your program...
    require_once 'DB.php';

    $db =& DB::connect('pgsql://usr:pw@localhost/dbnam');
    if (PEAR::isError($db)) {
        die($db->getMessage());
    }

    // Proceed with a query...
    $res =& $db->query('SELECT * FROM clients');

    // Always check that result is not an error
    if (PEAR::isError($res)) {
$db->disconnect(); //??????????
        die($res->getMessage());
    }

................
working

$db->disconnect();//??????????

return $value;
    ?>

Solution

  • No you don't need to disconnect from a database. It might be helpful for a long running script to use this operation, but your connection gets closed once the script has finished anyway.