当我运行以下PHP代码时:
<?php
$username = "root";
$password = "allen123";
$conn = new PDO('mysql:host=localhost;dbname=test', $username, $password);
?>
我收到以下错误。
致命错误:未使用的异常'PDOException',消息'SQLSTATE [HY000] [2002]否&gt;这样的文件或目录'在/Users/idrisk/Colourity/site/index.php:4堆栈跟踪:#0&gt ; /Users/idrisk/Colourity/site/index.php(4):PDO-&gt; __ construct('mysql:host = loca ...','root',&gt;'allen123')#1 {main}抛出在/Users/idrisk/Colourity/site/index.php第4行
有什么想法吗?我通过Macports下载了PDO驱动程序
修改
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php55/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to the path
to your MySQL server's socket file.
For mysql5, use /opt/local/var/run/mysql5/mysqld.sock
For mysql51, use /opt/local/var/run/mysql51/mysqld.sock
For mysql55, use /opt/local/var/run/mysql55/mysqld.sock
For mysql56, use /opt/local/var/run/mysql56/mysqld.sock
For mariadb, use /opt/local/var/run/mariadb/mysqld.sock
For percona, use /opt/local/var/run/percona/mysqld.sock
---> Cleaning php55-mysql
---> Updating database of binaries: 100.0%
---> Scanning binaries for linking errors: 100.0%
---> No broken files found.
答案 0 :(得分:2)
看起来你的php.ini文件中有一个无效的套接字。将pdo_mysql.default_socket
设置更改为空字符串以使用默认套接字。