Connecting to remote mysql works in terminal, not via PHP PDO script

后端 未结 3 1757
一生所求
一生所求 2021-01-17 03:52

I am facing a weird problem here we have a server A where the app files are stored and B server with database

Tried to connect via command prompt from server A to B

3条回答
  •  温柔的废话
    2021-01-17 04:25

    Try specifying the port in your connection string and ensure the database server is set to allow remote connections and the port is open on your firewall (both of these I suspect are already done as you are able to connect via the terminal but it never hurts to verify and check things).

    Change your PDO connection and add the port=3306 or if you're using MAMP use port 8889

    $this->db=new PDO('mysql:host=xx.xx.xx.xx;port=3306;dbname=databasename','root','password');
    

    Another thing to check is if – SELinux is blocking network connections. Login as root and run

    setsebool -P httpd_can_network_connect=1
    

提交回复
热议问题