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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路