Reputation: 15451
I have been trying to connect to my database using pdo on godaddy with no successs.
Initially i got the error:
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Then i look around the web, found out that i need to change the part to socket. I looked for my socket found it and changed it using unix_socket=/tmp/mysql-1.sock
. Now i get the error:
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql-1.sock' (2)
I have also tried changing the host and hostname to the IP address of server hosting the database and still get the same error.
Please can someone help me. Im hosting on godaddy.
Thanks in advance.
EDIT #1
$dbh = new PDO('mysql: hostname=122.100.111.0;port=3306;unix_socket=/tmp/mysql-1.sock; dbname=orson', 'username', 'password');
foreach($dbh->query('SELECT * from q_users') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
}
Upvotes: 2
Views: 5267
Reputation: 111
PDO is supported on the Linux hosting plans at GoDaddy but apparently has to be enabled through cPanel on some accounts:
Note: You may need to check other boxes that one would normally think are on by default (e.g. mysqli).
Spent some time tonight talking to GoDaddy tech support to figure this out and thought I would share.
Upvotes: 4
Reputation: 1
I'm having the same issue!
After looking through their forums, I've found Go Daddy's Windows platform does not support it, their Linux one however does. They do not charge you to switch.
Upvotes: 0
Reputation: 87
I had the same error. I think your hostname its wrong. Here´s a document where you can find your hostname. They do support PDO I have my entire application running with it.
http://support.godaddy.com/help/article/39/locating-your-databases-host-name
Upvotes: 0
Reputation: 15451
After exchanging messages with the Godaddy Support Team i found out that they don't support PDO on their shared hosting plan.
Upvotes: 0