1

This is my config.php code This works when I am on localhost but when I uploaded the site it does not work anymore. I tried searching here for answer but being a newbie makes my life hard.

<?php define("DB_HOST", "mysql.hostinger.ph"); 
define("DB_USER", "myuser");
define("DB_PASS", "mypassword");
define("DB_NAME", "mydbname");?>

And this is my Database.php code

    <?php 
$filepath = realpath(dirname(__FILE__));
include_once($filepath.'/../config/config.php');
?>
<?php
Class Database{
 public $host   = DB_HOST;
 public $user   = DB_USER;
 public $pass   = DB_PASS;
 public $dbname = DB_NAME;


 public $link;
 public $error;

 public function __construct(){
  $this->connectDB();
 }

private function connectDB(){
 $this->link = new mysqli($this->host, $this->user, $this->pass, 
  $this->dbname);
 if(!$this->link){
   $this->error ="Connection fail".$this->link->connect_error;
  return false;
 }
 }

// Select or Read data
public function select($query){
  $result = $this->link->query($query) or die($this->link->error.__LINE__);
  if($result->num_rows > 0){
    return $result;
  } else {
    return false;
  }
 }

// Insert data
public function insert($query){
 $insert_row = $this->link->query($query) or die($this->link->error.__LINE__);
 if($insert_row){
   return $insert_row;
 } else {
   return false;
  }
 }

// Update data
 public function update($query){
 $update_row = $this->link->query($query) or die($this->link->error.__LINE__);
 if($update_row){
  return $update_row;
 } else {
  return false;
  }
 }

// Delete data
 public function delete($query){
 $delete_row = $this->link->query($query) or die($this->link->error.__LINE__);
 if($delete_row){
   return $delete_row;
 } else {
   return false;
  }
 }

}

Then I get max user connection on Database.php line 22. I tried my best to search for a solution I hope that you can help my newbie mind ahhahah.

Galvezo.A
  • 11
  • 2

2 Answers2

0

I think the problem is not in your code,possible in the mysql server.There are options in mysql config file,like this:

myisam-recover-options  = BACKUP
max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10

The problem maybe is the max_connections,which means this will allow 100 connections to the server at most.

If you are use third-party mysql server,this problem may happen...

JWang
  • 181
  • 6
0

The most easiest reliable way is to contact your hosting provider. Most of the time, max user connection errors is solved this way.

Because usually you are not allowed (privileged) to execute useful queries to solve it(like Grant usage...) or change required configurations under a shared hosting environment.

But after all, it could be useful to read about it:

Community
  • 1
  • 1
behkod
  • 2,647
  • 2
  • 18
  • 33