0

I can't connect to my database. Have this error

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/1130): Host '31.170.160.93' is not allowed to connect to this MySQL server in /home/a7422059/public_html/includes/database.php on line 12

and in php it looks like

config.php

defined('DB_SERVER') ? null : define("DB_SERVER", "31.170.160.93");// or server29.000webhost.com
defined('DB_USER')   ? null : define("DB_USER", "*****");
defined('DB_PASS')   ? null : define("DB_PASS", "*****");
defined('DB_NAME')   ? null : define("DB_NAME", "a7422059_photo");

and connection

database.php

public function open_connection(){
        $this->connection = mysqli_connect(DB_SERVER , DB_USER , DB_PASS , DB_NAME);
        if(!$this->connection){
            die("Database connection failed:" . mysqli_error($this->connection));
        }
    }

what I'm doing wrong?

  • is db user has permissions to connect remotely (not only from localhost/127.0.0.1)? – mitkosoft May 19 '16 at 12:45
  • Possible duplicate of [Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server](http://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server) – mitkosoft May 19 '16 at 13:09

1 Answers1

0

If your DB server is different than the HTTP server (where PHP executes), you've got to allow the user to connect from this host specifying host or "%" in the mysql's user table column "host" :

CREATE USER 'toto'@'%' IDENTIFIED BY '***';
GRANT USAGE ON * . * TO 'toto'@'%' IDENTIFIED BY '***'
WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 
MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;

This is a sample query executed by phpMyAdmin when you create a user spécifiying the host as "%"

k4cy
  • 322
  • 3
  • 8