Error on creating connection to PDO in PHP

隐身守侯 提交于 2019-11-28 20:22:17
TML

Usually means that you need to specify TCP/IP (1), or tell MySQL where your Unix socket is (2):

  1. "mysql:host=127.0.0.1" or "mysql:host=localhost;port=3306"
  2. "mysql:unix_socket=/var/run/mysqld/mysqld.sock"

You can also use 127.0.0.1, rather than specifying "localhost", in your db connection string to avoid this issue altogether.

You might want to modify php.ini so PDO can find mysql.sock by specifying the pdo_mysql.default_socket = /opt/lampp/var/mysql/mysql.sock (in the case of xampp). Don't forget to restart Apache after changing php.ini.

(Sorry, this seems to be a repeated solution).

I'm using MAMP 2.0.1 and Symfony 1.4 with Doctrine for this project.

Third option worked for me with a small modification: in /config/databases.yml

dsn: 'mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=MY_DB_NAME;'
pilsetnieks

The most common cause of an error like this would be that MySQL isn’t running.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!