所以我终于安装了PDO驱动程序,现在我又遇到了另一个问题。当我尝试使用
时<?php
$username = "root";
$password = "allen123";
$conn = new PDO('mysql:host=localhost;dbname=test', $username, $password);
?>
只是连接到数据库,我收到以下错误
致命错误:未捕获的异常&#39; PDOException&#39;与消息 &#39; SQLSTATE [HY000] [2002]没有这样的文件或目录&#39;在 /Users/idrisk/Colourity/site/index.php:4堆栈追踪:#0 /Users/idrisk/Colourity/site/index.php(4): PDO-&gt; __ construct(&#39; mysql:host = loca ...&#39;,&#39; root&#39;,&#39; allen123&#39;)#1 {main} 第4行/Users/idrisk/Colourity/site/index.php投放
我已经看过关于这个问题的关于SO的其他帖子,但它们看起来都不一样。有什么想法吗?
编辑
所以我通过Macports安装了这些驱动程序,这是我安装后的内容
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 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`
其他答案说要用别的东西。