mysql连接超时

bq8i3lrv  于 2021-06-23  发布在  Mysql
关注(0)|答案(0)|浏览(354)

我有一个codeigniterweb应用托管在awsec2上(php7和pdo用于连接到db)和数据库设置在awsrdsmysql上。为了获得unicode支持,我用utf8mb4字符集重新创建了数据库和所有表。现在我的ci应用程序给我一个连接超时。我试着从localhost连接到新的数据库,效果很好。

$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 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
);

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题