Username (e.g. epiz_XXX) or Website URL
Username: epiz_33045611
The website url: http://gladdigital.rf.gd/
Error Message
SQLSTATE[HY000] [1203] User epiz_33045611 already has more than ‘max_user_connections’ active connections
Other Information
Hi, everyone. I am a total newbie when it comes to hosting. I have built a php pdo with mvc model website. The first problem I ran into is redirecting the user to a subfolder called public but I have solved it with a solution from this forum. After that, I added the database through the vpanel, I ran into this error.
I have read this post about max_user_connection.
- If you’ve written the code yourself, make sure that you’re only creating one database connection for every request. I’ve seen scripts which create a new database connection for every database query, and never close connections, which makes it easy to have a lot of connections open at the same time.
- Especially if you have slow running code, it might be a good idea to manually close connections and reopen connections after your queries. This should also help reduce the number of active connections.
I have coded the php scripts myself and I’m not sure if I have written a good code or not. After googling the error message, I found a stackoverflow post that says I need to set the PDO::ATTR_PERSISTENT
to false
. In my code, I have the persistent connection set to true because I was following a tutorial on youtube. When I change it to false
, I get ERR_TOO_MANY_REDIRECTS
error message, so I changed it back to true
. I still don’t what to do. What do I need to change in my code?
I have the database connection in Database.php file. Here is the construct method.
class Database
{
private $host = DB_HOST;
private $db_name = DB_NAME;
private $user = DB_USER;
private $pass = DB_PASS;
private $dbh;
private $stmt;
public function __construct()
{
$dsn = "mysql:host=" . $this->host . ";dbname=" . $this->db_name;
$option = [
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];
try {
$this->dbh = new PDO($dsn, $this->user, $this->pass, $option);
} catch (PDOException $e) {
die($e->getMessage());
}
}
...
And in the model files, I have this constructor method:
class UsersModel
{
private $table = "users";
private $db;
public function __construct()
{
$this->db = new Database();
}
public function getUserData($username)
...
{
I assume this is not a good way to make connections because this produces so many connections. I also don’t close the connection (I don’t know if I should close the connection after every query or not).
So, if someone can help me and tell me what I need to do or what part in my code I need to fix, I would appreciate it so much. Thank you so much in advance.