1

So I just finally installed the PDO drivers, and now I have another issue. When I try to use

<?php
$username = "root";
$password = "allen123";
$conn = new PDO('mysql:host=localhost;dbname=test', $username, $password);
?>

Just to connect to the DB, I get the following error

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Users/idrisk/Colourity/site/index.php:4 Stack trace: #0 /Users/idrisk/Colourity/site/index.php(4): PDO->__construct('mysql:host=loca...', 'root', 'allen123') #1 {main} thrown in /Users/idrisk/Colourity/site/index.php on line 4

I've looked at other posts on SO about this issue, but they all seem different. Any ideas?

EDIT

So I installed the drivers via Macports and this is what I get once It was installed

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`

The other answers say to use something else.

  • 2
    See http://stackoverflow.com/questions/1819592/error-when-connecting-to-mysql-using-php-pdo – Michael Berkowski Apr 16 '14 at 00:03
  • You need to verify what your mysql installation path is and locate the .sock file. Is the mysql server actually running? If not, you won't have a socket either. So start looking to find where MySQL's data directory ended up and set PDO's socket path to point to the correct location. – Michael Berkowski Apr 16 '14 at 00:16
  • This is what I now get `Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in /Users/idrisk/Colourity/site/index.php:4 Stack trace: #0 /Users/idrisk/Colourity/site/index.php(4): PDO->__construct('mysql:host=loca...', 'root', 'allen123') #1 {main} thrown in /Users/idrisk/Colourity/site/index.php on line 4` @Michael –  Apr 16 '14 at 00:29
  • You're partway there then. You're now connecting to the service, but root's password is incorrect. Did you set a root password? Typically, MySQL installs with a blank one and you set it as part of initializing the service. – Michael Berkowski Apr 16 '14 at 01:22

0 Answers0