Why does PDO print my password when the connection fails?

后端 未结 4 575
甜味超标
甜味超标 2020-12-13 06:08

I have a simple website where I establish a connection to a MySQL server using PDO.

$dbh = new PDO(\'mysql:host=localhost;dbname=DB;port=3306\',
                     


        
4条回答
  •  情话喂你
    2020-12-13 06:35

    A simple workaround is to catch the PDOException thrown by the PDO constructor:

    try {
        $dbh  =  new PDO('mysql:host=localhost;dbname=DB;port=3306', 'USER',
        'SECRET', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
    } catch (PDOException $e) {
        throw new Exception($e->getMessage());
    }
    

提交回复
热议问题