how to connect to database on another server

前端 未结 8 1211
孤独总比滥情好
孤独总比滥情好 2020-12-03 02:05

Could I have my php scripts on server A and connect to the MySQL database on server B?

If yes, how it would be done? Thanks in advance

8条回答
  •  暖寄归人
    2020-12-03 02:34

    Yes it can be done.

    Find out the IP address of the server A where your scripts will be uploaded. Do not forget to change the localhost to the ip address of the Server B in mysql_connect() or mysqli_connect() method.

    Now go the control panel of the Server B where your Database is.

    In the control panel's Homepage go the databases section and click the Remote MYSQL option.

    Then add the Ip address of the Server A and click on add host.

    Now you can access to the database in Server B while your scripts are running in Server A. Mind you the fetched result will be slow cause it is getting data from database that is located on another server.

    Your welcome

提交回复
热议问题