PDOException: SQLSTATE[HY000] [2002] No such file or directory

前端 未结 10 2132
太阳男子
太阳男子 2020-12-05 11:19

I have put PushChatServer dir in htdocs folder and create database puschat try to run @\"http://localhost/PushChatServer/api/test/database.php\"

Then I got following

10条回答
  •  春和景丽
    2020-12-05 11:45

    I had the same error using PHP 5.6.30 (macOS Sierra) with the simple PDO code like:

    $pdo = new PDO('mysql:host=localhost;dbname=db_php', 'root', '');
    

    And I received the same error message. To fix, I changed "localhost" for IP (loopback) "127.0.0.1" in my code:

    $pdo = new PDO('mysql:host=127.0.0.1;dbname=db_php', 'root', '');
    

    To test the connection:

    $ php -r "new PDO('mysql:host=127.0.0.1;dbname=db_php', 'root', '');"
    

    This work's for me!

提交回复
热议问题