svk
svk

Reputation: 4553

Whats wrong with PDO connection?

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.

Upvotes: 1

Views: 770

Answers (2)

Nazariy
Nazariy

Reputation: 6088

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.

Upvotes: 2

Wilbo Baggins
Wilbo Baggins

Reputation: 2751

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.

Upvotes: 0

Related Questions