在我的AWS EC2服务器中,我有两个项目:
当我在localhost中时,此代码有效,但是当我放入真正的主机时,它失败了:
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'kendozone.cp90iogazqzc.us-west-2.rds.amazonaws.com',
'database' => 'mydb',
'username' => 'myuser',
'password' => 'mypas',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'ken_',
'port' => '3306'
));
这是错误消息:
Uncaught PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in ...
我错过了什么????
答案 0 :(得分:2)
<?php
$dbhost = $_SERVER['RDS_HOSTNAME'];
$dbport = $_SERVER['RDS_PORT'];
$dbname = $_SERVER['RDS_DB_NAME'];
$dsn = "mysql:host={$dbhost};port={$dbport};dbname={$dbname}";
$username = $_SERVER['RDS_USERNAME'];
$password = $_SERVER['RDS_PASSWORD'];
$dbh = new PDO($dsn, $username, $password);
?>
您错过了该端口。 AWS REFERENCE