Forum Moderators: coopster

Message Too Old, No Replies

Problem with MySQL DB Connection Class not closing.

         

pblancher

1:25 am on Jun 8, 2006 (gmt 0)

10+ Year Member



Someone I used to work with built this and I use it on all of my items now. However it appears that it is not closing the database connection like its suppose to. I have a lot of MySQL processes running on the server that shouldnt be as many. The Class is below as is how its used in the code.

/////////////////////////////////////////////
class DB {
function DB() {
$this->host = "localhost";
$this->db = "database";
$this->user = "username";
$this->pass = "password";
$this->link = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->db);
}

function close() {
mysql_close($this->link);
}
}
///////////////////////////////////////////////
To use it.
$sql="A query goes here";
$open_db = new DB; // Opens the connection
$result=mysql_query($sql);
$open_db.close; // Closes the connection

////////////////////////////////
In the error log...

[error] PHP Notice: Use of undefined constant close - assumed 'close' in /web1/www.user.com/admin/item/add.php on line 57

//////////////////////////////

TIA

eelixduppy

2:30 am on Jun 8, 2006 (gmt 0)



You are missing the parenthesis. The line should look like this:
$open_db.close();

dreamcatcher

6:56 am on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it also missing the class operator?

$open_db.close;

Try:

$open_db->close();

dc