I've built a site that accesses a mysql database through a class I have constructed. Here is how it is constructed (I've omitted a lot of the functions, but hopefully you get the idea...)
class MySQLDB
{
function MySQLDB(){
/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
}
function somefunction($u) {
$q = "SELECT something FROM table WHERE this = '$u'";
$r = mysql_query($q, $this->connection);
$row = mysql_fetch_row($r);
return $row[0];
}
};
$database = new MySQLDB
Everything works really well and fast and I can run queries buy using $database->somefunction($u); from any other page in the site.
The problem is every once in a while I get the sleep() processes that will cause the site to hang until the sleeps are timed out (which seems to be 60 seconds). If a user submits a new query while a sleep() is in process, it will create another sleep() that goes for another 60 seconds.
I read that you need to close your connections with the mysql_close(); to stop connections from timing out, but when I did this in my code it throws errors when it tried to run another query.
So, should I not be using the class? should I be using a mysql_close() anywhere? Or is there something else going on here?
Thanks in advance!
Jim