我正在尝试从Amazon云实例连接到RDS,并且我一直收到此错误
SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'xxxxx' (4)
我可以通过MySQL Workbench连接到RDS而没有任何问题,但是当我尝试从实例连接时,会发生错误。这是连接到RDS的代码:
$this->_host = 'xxx';
$this->_user = 'xxx';
$this->_password = 'xxx';
$this->_dbname = 'xxx';
$dns = 'mysql:host=' . $this->_host . ';dbname=' . $this->_dbname . ';port=3306';
$options = array(
\PDO::ATTR_PERSISTENT => true,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
);
try {
$this->handler = new \PDO($dns, $this->_user, $this->_password, $options);
} catch (\PDOException $e) {
die($e->getMessage());
}