Confusing PDO-only problem : Can't connect through socket/Access denied/Can't connect to server (shared host)

前端 未结 14 1885
失恋的感觉
失恋的感觉 2020-12-08 12:07

So the problem changed from what it was, i\'ll leave the original question below to prevent bad reviews on answers like I had after someone editing his question I answered :

相关标签:
14条回答
  • 2020-12-08 12:33

    I had the problem that production version worked just fine and a test version wasn't able to connect PDO :/ both versions was located at same servers, test in a sub directory.

    The fix was replacing in DSN the localhost for ip.

    'mysql:host=localhost;dbname=db'
    

    became

    'mysql:host=127.0.0.1;dbname=db'
    
    0 讨论(0)
  • 2020-12-08 12:37

    For what it's worth, I found this page after having the exact same issue. I am on a server running Apache & PHP only - MySQL is installed on another machine. I tried both the DNS name of the server and its IP and confirmed I could ping it. A PHP app on the same machine is talking to the database fine, using old syntax mysql_connect( ). But PDO from the CLI was throwing this error.

    The solution for me was to check my DSN. Any typo in the DSN itself is ignored silently, and PDO assumes you mean localhost. My issue was I had "name=" instead of "dbname=" in the DSN.

    0 讨论(0)
提交回复
热议问题