开发者

I have a problem connecting to my db on godaddy with PDO

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)

The开发者_开发知识库n 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/>";

}


PDO is supported on the Linux hosting plans at GoDaddy but apparently has to be enabled through cPanel on some accounts:

  1. Go to cPanel from Hosting menu under My Account.
  2. Go to "Select PHP version".
  3. Choose version of PHP in dropbox (e.g. 5.5) and click "Set as Current".
  4. Check the checkboxes of the features you want (e.g. PDO) and click "Save".

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.


After exchanging messages with the Godaddy Support Team i found out that they don't support PDO on their shared hosting plan.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜