Good way to open and close connections
Posted: Thu Nov 02, 2006 3:59 pm
Hi,
We've currently had a problem with our VPS server. We used too many resources.
I guess that the connection we have to read/write our database is the reason of this problem.
This is how we work:
sometimes up to 6-7 queries in one php-file
This all works great. But is it holding resources or not?
I was thinking that after the script is done, all connections will be closed automatically and the used resources are free again? Or am I thinking wrong. I'm not sure anymore
Is there another way to read the database? SQL is very time consuming on large database, even with a good index?
Thanks,
We've currently had a problem with our VPS server. We used too many resources.
I guess that the connection we have to read/write our database is the reason of this problem.
This is how we work:
Code: Select all
//Connection to localhost:
@ $handledb1 = mysql_connect("localhost","user","password");
mysql_select_db("namedb1", $handledb1);
//Connection to database on other server:
@ $handledb2 = mysql_connect("IP","user","password");
mysql_select_db("namedb2", $handledb2);
$query1 = "SELECT * FROM table WHERE field = '$value'";
$sql1 = mysql_query($query1, $handledb1);
$query2 = "SELECT * FROM table WHERE field = '$value'";
$sql2 = mysql_query($query2, $handledb2);This all works great. But is it holding resources or not?
I was thinking that after the script is done, all connections will be closed automatically and the used resources are free again? Or am I thinking wrong. I'm not sure anymore
Is there another way to read the database? SQL is very time consuming on large database, even with a good index?
Thanks,