Whats wrong with PDO connection?

自作多情 提交于 2020-01-05 07:03:10

问题


Possible duplicate of this

I am connecting the DB using the PDO.

      $DBH = new PDO('mysql:host=localhost;dbname=name','dbusername','dbpassword'); 

This is not working here.

I am getting the error

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

But whatever the connection we already done in mysql_connect thats working fine.Could you please help me on this.


回答1:


Some web hosting providers use custom domain names or IP addresses for MySQL connection, I would advise you first of all to check hosting manual on database connections.
Usually by creating MySQL database through control panel, you would receive example of database connection properties.




回答2:


Change localhost to 127.0.0.1 to enforce a connection over TCP rather than a socket connection. My guess is that'll make things work for you.



来源:https://stackoverflow.com/questions/8807113/whats-wrong-with-pdo-connection

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