When working on a file, I open and close connections like this:
require("../StoredProcedure/connect.php");//users.user_id
//..some query and code
mysql_close();
I do that multiple times for the whole file.. is it more efficient, to open the connection once instead and close it at the end of the file instead..
I also get the error message:
No database selected
But I do require the connect file with teh database selected..why do I get that message?
That is what is inside the file:
<?
$conn=mysql_connect("localhost","root","") or die(mysql_error);
mysql_select_db("politicalforum",$conn);
?>
The connection works..I tried with other queries
If you are having multiple connections to a database in one program/instance and everytime you call
The best policy for a database connection in a script is to call it the first time you need it and close it the last time you will use it. Basically at the top and bottom of the script.
On a side note:
is faster than require and if you can use single quotes around everything. Your script will execute faster with less strain on your server resources.