数据库连接successfully....but...以下是我的代码
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'databasename';
mysql_connect($host, $user, $pass) or die ("Database Not Connected");
mysql_select_db($db) or die ("Database Not Fount");
?>但是数据库经常在30-40 minutes....please后断开连接,这是怎么回事.
发布于 2010-01-03 03:47:50
不要忘记关闭与mysql_close()的连接。
太多的连接会导致问题,所以这可能会解释你的连接断开。
发布于 2010-01-03 03:37:28
这可能是混淆变量的问题。您的连接和db选择不应与稍后运行的查询混淆。
$conn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$query = "SELECT id, username FROM users";在本例中,$conn将不会用于引用除我的资源之外的任何内容。我的查询将被称为$query,这样就不会把我自己搞糊涂了。
我还建议观察查询的执行时间,以及打开的并发连接的数量。如果需要,请务必关闭连接:
mysql_close($conn); // note the importance of a unique variable herehttps://stackoverflow.com/questions/1992566
复制相似问题