私はこのエラーに何日も悩まされており、修正する方法が見つかりません。私は実装しようとしました
- シングルトン データベース オブジェクト
- クエリ後に接続を閉じる
- 永続接続を試行しています
- 最大接続数を 250 (ローカル) に設定する
- 最大ユーザー接続数の設定 250 (ローカル)
これは他の誰かに起こりましたか?
奇妙なのは、私のローカル サーバーのエラー メッセージはConnection failed: SQLSTATE[08004] [1040]
、行がまだ挿入されており、データベース クエリが機能していることです。
運用サーバーでは、エラー メッセージはConnection failed: SQLSTATE[42000] [1203] User db_admin already has more than 'max_user_connections' active connections
I know maximum connections is set to 15, but I have Consulted support and they have said I have no connections at the time of this error. になります。
私のすべてのオプションの後、誰かが私のコードをチェックして、これらのエラーを作成する可能性のあるエラーがないことを確認できますか?
class MyPDO extends PDO{
const DB_HOST='localhost';
const DB_PORT='3306';
const DB_NAME='db_name';
const DB_USER='db_admin';
const DB_PASS='SECRET';
public function __construct(){
parent::__construct('mysql:host='.MyPDO::DB_HOST.';port='.MyPDO::DB_PORT.';dbname='.MyPDO::DB_NAME,
MyPDO::DB_USER,MyPDO::DB_PASS);
try{
$this->db = new MyPDO();
$this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
}catch(PDOException $e){
//always catching the connection errors
echo 'Connection failed: ' . $e->getMessage();
}
}
public function query($query){
$args = func_get_args();
array_shift($args);
//check inputs
var_dump($args);
$reponse = parent::prepare($query);
$reponse->execute($args);
return $reponse;
}
}
ここに挿入クエリがあります
function InsertUserToSql()
{
$ret = $this->db->query("INSERT INTO CD_USERS (email,username,password,fname,lname,dob,gender) VALUES
(?,?,?,?,?,?,?)",$this->Email,$this->Username,$this->Password,$this->Fname,
$this->Lname,$this->Birthday,$this->Gender);
if($ret){
echo "insert success";
return $this->db->lastInsertId();
}
$this->db = null;
}