Php/mySQL 连接到远程服务器, fatal error ,连接超时

标签 php mysql pdo

我在 DigitalOcean 拥有一个 Droplet,在另一家托管提供商处拥有一个带有域名的网络空间。我无法访问其他服务器上除 ftp 之外的任何内容。在另一个网络空间上,我有一个 php 脚本,我想远程连接到我的 Droplet 上的 mySQL 数据库。我在防火墙中打开了端口 3306,添加了一个可以从 % 访问该表的用户,并更改了配置文件中以“bind-adress”开头的行(也尝试注释掉)。尝试连接时仍然遇到这样的错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] 
[2002] Connection timed out' in {the url to the script that's trying to connect}:19 
Stack trace: #0 {the url to the script that's trying to connect}(19): PDO->__construct('mysql:host={my droplet public ip}, '{username}', '{password}') #1 {main} 
thrown in {the url to the script that's trying to connect} on line 19

PHP 中的连接部分如下所示:

$db = new PDO('mysql:host={droplet public ip};port=3306;dbname={database name};charset=utf8', '{username}', '{password}');

我做错了什么?!

最佳答案

当我联系“其他托管公司”的支持时,他们告诉我,他们的服务器上不允许对另一个数据库的传入或传出请求。尽管如此,他们今天早上早些时候告诉我允许发出请求。

关于Php/mySQL 连接到远程服务器, fatal error ,连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33844829/

相关文章:

php - (PHP) 使用两个表进行登录查询;其他用户未登录?

php - UPS Time in Transit 服务代码到 Rating API

php - JQuery 移动登录页面

PHP runkit_function_rename 不起作用?

php - PDO:MySQL 服务器已消失

mysql - 使用OrientDB在Windows系统上执行.sql文件导入数据

mysql - 解决调用 mysql_real_escape_string() 时出现的 "Access denied"错误

php - 使用嵌套的 foreach 循环取消设置数组中的对象无法按预期工作?

php - 使用 2 GROUP_CONCAT 安全吗?

php pdo 只从 mysql 获取一个值;等于变量的值