首次部署应用后,我收到以下错误:数据库连接失败:连接超时(2002)
这是我的连接PHP代码:
defined('DBSERVER') ? null : define("DBSERVER", "<my_ip_address>");
defined('DBUSER') ? null : define("DBUSER", "<db_username>");
defined('DBPASS') ? null : define("DBPASS", "<db_password>");
defined('DBNAME') ? null : define("DBNAME", "<db_name");
private $connection;
function _construct() {
$this->openconnection();
}
public function openconnection() {
$this->connection = mysqliconnect(DBSERVER, DBUSER, DBPASS, DBNAME);
if(mysqliconnecterrno()) {
die("Database connection failed: " .
mysqliconnecterror() .
" (" . mysqliconnecterrno() . ")"
);
}
}
答案 0 :(得分:0)
如果你在其他机器上有Mysql数据库而不是你必须允许来自mysql配置的所有IP地址,是的你还必须在服务器中为Mysql端口添加防火墙例外。