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

前端 未结 14 1884
失恋的感觉
失恋的感觉 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:16

    Can you try 127.0.0.1 as the server name instead of localhost?

    IIRC, with some mySQL drivers / adapters, this decides whether the socket is used for establishing the connection or not.

    0 讨论(0)
  • 2020-12-08 12:18

    Using the connection which works, run the query:

    show variables like 'socket';
    

    (this behaves just like a select statement)...and you'll get the path of the running socket.

    Then check the file permissions.

    0 讨论(0)
  • 2020-12-08 12:21

    One year later, I found a solution for this issue : using a SQLite database. PDO worked fine, but not with MySQL

    ** EDIT ** as everyone is downvoting this: This solved my issue (I'm the OP). I was using Doctrine, so switching RDBMS was easy and quick. Also the website was some a home made CMS, with very few trafic, so SQLite was fine.

    I know it's not a real "Answer" to the problem, but if someone is in the same context: a crappy shared hosting which you can't change with this weird PDO-MySQL bug AND is using doctrine. This IS a solution. I can delete this answer, but if I had thought of this at the time of the OP, I would have saved a lot of time.

    0 讨论(0)
  • 2020-12-08 12:24

    Is your server running with SeLinux enabled (enforcing)? If it is, try running as root:

    # setsebool -P httpd_can_network_connect on
    
    0 讨论(0)
  • 2020-12-08 12:24

    I found the reason for the strange behaviour. If bind-address is different to 127.0.0.1 or 0.0.0.0 (all addresses) PDO can't connect to 127.0.0.1.

    0 讨论(0)
  • 2020-12-08 12:27

    The Issue In the Mysql configuration It you need to disable the option of skip-networking in my.conf configuration file this should work fine reference http://www.wolfcms.org/forum/post7098.html#p7098

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