我无法连接到我的数据库。有这个错误
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
并在php中看起来像
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");
和连接
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));
}
}
我做错了什么?
答案 0 :(得分:0)
如果您的数据库服务器与HTTP服务器(PHP执行的地方)不同,您必须允许用户从指定主机的主机或mysql的用户表列“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;
这是一个示例查询,当您创建将主机定为“%”的用户时,由phpMyAdmin执行