doufen3838 2012-03-10 23:15
浏览 78
已采纳

我需要使用mysql_close(连接)吗?

I have the following code in db.php to connect to my DB.

<?php
$DB_HOST        = "localhost";
$DB_NAME        = "db";
$DB_USER        = "user";
$DB_PASSWORD        = "pass";

$con = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD);

if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db($DB_NAME , $con);
?>

In my other script I include it using:

include("db.php");

In some cases I receive the ff error:

[10-Mar-2012 10:47:20] PHP Warning: mysql_connect() [function.mysql-connect]: User db_user already has more than 'max_user_connections' active connections in /home/user/public_html/sc/db.php on line 8

Now, I am wondering if I need to close the connection like:

<?php
include("db.php");

//other stuff here

mysql_close($con);
?>

BTW, I have a value of 100 max_connections in my MySQL config.

I also research about persistent connection and I believe my code above is not a persistent connection.

  • 写回答

2条回答 默认 最新

  • dtra49684 2012-03-12 06:34
    关注

    No, this won't help you if you close it at the end of the script. mysql_close() is just useful in case you want to free up resources before you end your script, because your connection is closed as soon as execution of the script ends

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题