开发者

server is disconneting database

database get connected successfully....but... here is my code

<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'da开发者_如何转开发tabasename';

mysql_connect($host, $user, $pass) or die ("Database Not Connected");
mysql_select_db($db) or die ("Database Not Fount");

?>

but the database is regularly disconnecting and connecting after 30-40 minutes....please help me, that what's going on.....


Don't forget to close your connection with mysql_close().

Too many connections will cause problems so that might explain your disconnects.


This may be the problem of confusing variables. Your connection and db-selection shouldn't be confused with queries that will run at a later time.

$conn = mysql_connect($host, $user, $pass) or die(mysql_error());
        mysql_select_db($db) or die(mysql_error());

$query = "SELECT id, username FROM users";

In this example, $conn will not be used to reference anything other than my resource. My query, ran at a later time, will be known as $query, so as to not confuse myself.

I would also suggest watching the execution times of your queries, and the number of concurrent connections opened. If you need to, be sure to close your connections:

mysql_close($conn); // note the importance of a unique variable here
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜