Page 1 of 1
simple question about mysql_close()
Posted: Sat Apr 23, 2005 5:56 am
by bytte
As the title says, this is a simple question.
If I open the same mysql database a few times on a PHP page, should I close it everytime after I made a connection?
Or is it sufficient to put mysql_close() at the end of the page to close all open connections to that same database?
Posted: Sat Apr 23, 2005 6:07 am
by Phoenixheart
But why do you have to do several mysql_connect() on just one page? I think one connect is enough?
Posted: Sat Apr 23, 2005 6:08 am
by crazytopu
Why dont you use a class instead ?
Code: Select all
<?php
class DbConnector {
var $theQuery;
var $link;
//*** Function: DbConnector, Purpose: Connect to the database ***
function DbConnector(){
// Get the main settings from the array we just loaded
$host = 'dbhost';
$db = 'dbname';
$user = 'dbusername';
$pass = 'dbpassword';
// Connect to the database
$this->link = mysql_connect ($host, $user, $pass)or die ("Unable to connect to Database Server");
mysql_select_db($db)or die ("There is no such database");
register_shutdown_function(array(&$this, 'close'));
}
//*** Function: close, Purpose: Close the connection ***
function close() {
mysql_close($this->link);
}
}
?>
Posted: Sat Apr 23, 2005 9:41 am
by Bill H
You might look into the usage of the mysql_pconnect() function.
It may have advantages to viewer and to server.