dongruo0909 2015-11-07 22:12
浏览 114
已采纳

未捕获的异常'PDOException' - 不允许主机'xxx'连接到此MySQL服务器

I get this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1130] Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server' in /home/.../public_html/php/default.php:10 Stack trace: #0 /home/.../public_html/php/default.php(10): PDO->__construct('mysql:host=...', '...', '...') #1 /home/.../public_html/php/login-status.php(8): getDB() #2 {main} thrown in /home/.../public_html/php/default.php on line 10

I've tried using localhost buy that doesn't work as i'm using a web hosting provider and their MySQL server is external.

This is my code for accessing the db:

$dbHost = '...';
$db = '...';
$dbUser = '...';
$dbPass = '...';

$db = new PDO("mysql:host=$dbHost;dbname=$db;charset=utf8", $dbUser, $dbPass);

('...' is censored info)

  • 写回答

1条回答 默认 最新

  • dox19458 2015-11-07 22:29
    关注

    A few things:

    1) Make sure you can connect to that port.
    2) Make sure the connection string is correct for the specific type of database you are trying to reach
    3) Ensure that your IP address is on the whitelist for allowed access, you wouldn't want the world to be able to connect to it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料