bfinke
11-06-2009, 12:08 AM
Right now I have a file called db.php that connects to my DB using a function like this:
$dbcnx = @mysql_pconnect($dbhost, $dbtable, $dbpass)
or die("The site database appears to be down.");
if ($dbselection!="" and !@mysql_select_db($dbselection))
die("The site database is unavailable.");
Now I am rather new to programming but we just setup on a new dedicated server and the site is running very slowly. I talked with the server manager and he says the MySql is eating up the resources and making it go very slow.
I THINK the problem is that before each SQL query, I have the code run the function above to connect to the DB first. Am I creating too many connections to the DB per user? What is the best way around this?
Should I be using mysql_connect instead? Would that require me to close the sql connection? (I am not closing any sql connection now).
Or should I stop calling the function to donnect to the DB before every query?
The reason I am not sure is that I have a file called accesscontrol.php that includes db.php and accesscontrol.php is called on every single page after a user logs in. So if I should be using mysql_pconnect still, how do I make it so it is called only once? If I go to mysql_connect, is this a good idea and do I need to close the connection thereafter?
THANKS THANKS THANKS!!!
$dbcnx = @mysql_pconnect($dbhost, $dbtable, $dbpass)
or die("The site database appears to be down.");
if ($dbselection!="" and !@mysql_select_db($dbselection))
die("The site database is unavailable.");
Now I am rather new to programming but we just setup on a new dedicated server and the site is running very slowly. I talked with the server manager and he says the MySql is eating up the resources and making it go very slow.
I THINK the problem is that before each SQL query, I have the code run the function above to connect to the DB first. Am I creating too many connections to the DB per user? What is the best way around this?
Should I be using mysql_connect instead? Would that require me to close the sql connection? (I am not closing any sql connection now).
Or should I stop calling the function to donnect to the DB before every query?
The reason I am not sure is that I have a file called accesscontrol.php that includes db.php and accesscontrol.php is called on every single page after a user logs in. So if I should be using mysql_pconnect still, how do I make it so it is called only once? If I go to mysql_connect, is this a good idea and do I need to close the connection thereafter?
THANKS THANKS THANKS!!!