I have a Codeigniter web app hosted on AWS EC2 (PHP7 and PDO is used to connect to db) and database setup on AWS RDS Mysql. To get unicode support I recreated the database and all tables in utf8mb4 charset. Now my CI app give me a connection timeout. I tried connecting to the new db from localhost and it worked perfectly.
$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();
}
Here is my CI database.php
$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
);