I've been stumped on this error for days now and I can't find a way to fix it. I've tried to implement
- Singleton database object
- Closing my connections after queries
- Trying a persistence connection
- Setting max connection to 250 (local)
- Setting max user connections 250 (on local)
Has this occurred to anyone else?
What's weird is the error message on my local server is Connection failed: SQLSTATE[08004] [1040]
but the rows are still inserts and database queries work.
On the production server, the error message becomes 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 had no connections at the time of this error.
After all my options, can someone check my code to make sure that there's no errors in it that can be creating these errors?
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;
}
}
Here is the insert query
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;
}