Undefined property: PDO::$connect_error

后端 未结 3 1052
孤城傲影
孤城傲影 2021-01-26 08:10

I am trying to use $dbc->connect_error to check if any error occurs while trying to connect to my databease. I always get an error page saying:

3条回答
  •  长情又很酷
    2021-01-26 09:12

    There is no connect_error. You should use exception:

    try {
        $dbh = new PDO($dsn, $user, $password);
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }
    

    Or if you do not want exception you can try errorCode and errorInfo

提交回复
热议问题