【发布时间】:2017-07-22 15:40:49
【问题描述】:
当我刷新 php 页面时,mysql 创建了新的线程连接,由于 max_user_connection 的限制,这会导致共享主机上的问题。限制为 30,我刷新页面 30 次,mysql 停止并显示User already has more than 'max_user_connections' active connections。
我认为我设置正确但找不到解决方案。
db.php
$host="localhost";
$user="root";
$pass="";
$db="terind";
mysql_connect($host,$user,$pass);
mysql_select_db($db);
mysql_query("set names 'utf8'");
head.php
require("db.php");
...codes...
end.php
mysql_close();
index.php
require("head.php");
$check=mysql_fetch_assoc(...);
echo $check['index'];
require("end.php");
我该如何解决这个问题?
【问题讨论】:
-
停止使用
mysql_*函数。它们已被弃用,并且不支持准备好的语句(您应该使用它们)。此外,当脚本终止时,连接也应该被删除,除非您的共享主机由于某种原因使脚本保持活动状态。尝试在end.php末尾添加die()看看是否有帮助。 -
die(mysql_error()) 没有显示任何错误
标签: php mysql multithreading connection database-connection