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

前端 未结 10 2128
太阳男子
太阳男子 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:52

    Quick test (run in shell):

    php -r "new PDO('mysql:hostname=localhost;dbname=test', 'username', 'password');"
    

    SQLSTATE[HY000] [2002] No such file or directory means php cannot find the mysql.default_socket file. Fix it by modifying php.ini file. On Mac it is mysql.default_socket = /tmp/mysql.sock (See PHP - MySQL connection not working: 2002 No such file or directory)

    SQLSTATE[HY000] [1044] Access denied for user 'username'@'localhost' CONGRATULATION! You have the correct mysql.default_socket setting now. Fix your dbname/username/password.

    Also see Error on creating connection to PDO in PHP

提交回复
热议问题