我在AWS EC2上托管了Codeigniter Web应用程序(PHP7和PDO用于连接到数据库),并在AWS RDS Mysql上托管了数据库设置。为了获得unicode支持,我在utf8mb4字符集中重新创建了数据库和所有表。现在,我的CI应用程序为我提供了连接超时。我尝试从本地主机连接到新数据库,效果很好。
$servername = "*******.*******.us-east-2.rds.amazonaws.com";
$username = "*****";
$password = "*****";
try {
$conn = new
PDO("mysql:host=$servername;dbname=*****;charset=utf8mb4;", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
这是我的CI数据库。
$db['default'] = array(
'dsn' => $_SERVER['DSN'],
'hostname' => $_SERVER['DB_HOST'],
'username' => $_SERVER['DB_USER'],
'password' => $_SERVER['DB_PASSWORD'],
'database' => $_SERVER['DB_NAME'],
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8mb4',
'dbcollat' => 'utf8mb4_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);