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?
simple question about mysql_close()
Moderator: General Moderators
-
Phoenixheart
- Forum Contributor
- Posts: 123
- Joined: Tue Nov 16, 2004 7:46 am
- Contact:
-
crazytopu
- Forum Contributor
- Posts: 259
- Joined: Fri Nov 07, 2003 12:43 pm
- Location: London, UK
- Contact:
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);
}
}
?>