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

前提是你 提交于 2019-12-12 20:24:32

问题


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/>";

}

回答1:


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.




回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/3265145/i-have-a-problem-connecting-to-my-db-on-godaddy-with-pdo

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