我今天收到max_user_connections
錯誤。我想知道我是否做錯了什麼。做好多個連接的最佳做法mysqli
我有一個config.php
文件與mysqli的連接腳本:
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
所以,我需要得到的東西mysqli的網頁包括我的config.php。這裏有一個例子:
使用example.php
<?php
include_once("config.php");
$stmt = $mysqli->prepare("select...");
$stmt->execute();
$stmt->bind_result(...,...);
while($stmt->fetch()) {
...
}
$stmt->close();
?>
some html <p> <img>...
<?php
$stmt = $mysqli->prepare("select...");
$stmt->execute();
$stmt->bind_result(...,...);
while($stmt->fetch()) {
...
}
$stmt->close();
?>
some html <p> <img>...
<?php
$stmt = $mysqli->prepare("select...");
$stmt->execute();
$stmt->bind_result(...,...);
while($stmt->fetch()) {
...
}
$stmt->close();
?>
所以,我的問題是:是它做這樣的選擇最好的做法是什麼?我應該在每次選擇後關閉mysqli連接並再次打開?或者在頂部一起選擇,而不是與中間的一些HTML分開?
關於此錯誤消息,您的代碼沒有任何問題。所以這個問題在其他地方 –
它也可能是一個比max_user_connections大量的併發用戶。 – Mihai
這已被封閉作爲http://stackoverflow.com/questions/4079531/mysqli-error-user-already-has-more-than-max-user-connections-active-connectio的副本但是這裏的問題是明確的關於減少連接使用的編碼實踐,而對擬議副本的唯一討論是關於增加配置的限制。 – symcbean