AWS SQLSTATE [HY000] [2002]连接被拒绝

时间:2018-01-15 15:16:16

标签: php amazon-web-services amazon-ec2 amazon-rds

我是php和aws的新手,我遇到了一个试图将aws链接到简单登录php脚本的问题。

https://github.com/panique/php-login-minimal)。

我打印出以下错误:

  

SQLSTATE [HY000] [2002]拒绝连接

这是我的代码

<?php
    ob_start();
    session_start();

    //set timezone
    date_default_timezone_set('Europe/London');

    //database credentials
    define('DBHOST','instancename.cfci0i1rm4rl.us-east-2.rds.amazonaws.com');
    define('DBUSER','name_root');
    define('DBPASS','rootpassword');
    define('DBNAME','login');

    //application address
    define('DIR','https://union.washmel.com/user/login/auth/lr/');
    define('SITEEMAIL','noreply@domain.com');

    try {

        //create PDO connection
        $db = new PDO("mysql:host=".DBHOST.";charset=utf8mb4;dbname=".DBNAME, DBUSER, DBPASS);
        //$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);//Suggested to uncomment on production websites
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//Suggested to comment on production websites
        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    } catch(PDOException $e) {
        //show error
        echo '<p class="bg-danger">'.$e->getMessage().'</p>';
        exit;
    }

    //include the user class, pass in the database connection
    include('classes/user.php');
    include('classes/phpmailer/mail.php');
    $user = new User($db);
?>

如下是我网站上目前的错误链接。 https://union.washmel.com/user/login/auth/lr/index

0 个答案:

没有答案