mysql_select_db fail on somepage
I am making a social website for my company. The problem appears only in "diary" page. Most of time, my code connects to database successful, but sometime, it throws error:
Could not select database
This is my php code to connect to database on localhost:
function execute_action($query)
{
$link = mysql_connect("localhost", "root", "123456") or
die("Could not connect");
mysql_select_db("2t") or die("Could not select database");
$query = $query;
$result = mysql_query($query) or die("Query failed");
return $result ;
}
Do you have 开发者_高级运维any solution to help me. Thanks for reading.
As you arent closing your database connections between querys, so, my first thought would be is you're reaching a max connection barrier to the mySQL server.
While this may not be the answer - showing the mysql_error would help.
As someone else pointed out, theres no need to connect and drop each time. Unless your page has incredibly long processing time, connecting at the start, closing at the end should be enough.
You need to pass the dbconfiguration $link while selecting the db and executing the query
mysql_select_db("2t", $link)
even in mysql_query( $query, $link)
精彩评论