1

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.

Community
  • 1
  • 1
svk
  • 4,513
  • 18
  • 63
  • 100

2 Answers2

2

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.

Nazariy
  • 6,028
  • 5
  • 37
  • 61
0

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.

Wilbo Baggins
  • 2,701
  • 3
  • 26
  • 39
  • Its not in my localserver(wampor xamp).It is in my live server.So do you think it will work. – svk Jan 10 '12 at 17:02
  • If the code is executed on your live server then 127.0.0.1 should resolve to that server. If the code is not executed on your live server then localhost will surely never work. Should be easy to check though, why not give it a go. – Wilbo Baggins Jan 10 '12 at 17:07
  • localhost does sometimes work; I've had to use localhost when clients have used 123-reg hosting. – Ashley Banks Jan 10 '12 at 17:29