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

后端 未结 3 1677
一生所求
一生所求 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
    
    0 讨论(0)
  • 2021-01-17 04:26

    I don't know much about that, but try to place the port in back of the script:

    $this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password',3306);
    
    0 讨论(0)
  • 2021-01-17 04:41

    I got it working by running a command in the database server :)

    setsebool httpd_can_network_connect_db=1
    

    thanks for the replies yycdev

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