【发布时间】:2016-08-01 03:11:15
【问题描述】:
我注意到我从 $STH->fetch(PDO::FETCH_ASSOC) 的返回值是:
SQLSTATE[HY000] [1203] User *USERNAMEHERE* already has more than 'max_user_connections' active connections
我所有的查询都成功了,一切似乎都正常。
我认为我通过将连接分配为 NULL 来正确关闭连接。这是我的功能,你知道我为什么要最大化吗?
function mysql_read_single_row($sql, $array_of_values) {
try {
//create a connection
$DBH = new PDO("mysql:host=".CONST_MYSQL_HOST.";dbname=".CONST_MYSQL_DBNAME, CONST_MYSQL_RUSER, CONST_MYSQL_RPASS);
//set the sql
$STH = $DBH->prepare($sql);
//execute query
$STH->execute($array_of_values);
}
catch(PDOException $e) {
echo $e->getMessage();
return false;
}
$return_row = $STH->fetch(PDO::FETCH_ASSOC);
//close the connection
$STH = null;
$DBH = null;
//strip any escaped quotes from the data
$return_row = array_map('stripslashes', $return_row);
//return the array
return $return_row;
}
将 $STH 和 $DBH 设置为 null 是否不足以防止出现此错误?
【问题讨论】: