How to connect to a database on another server

Can I use my php scripts on server A and connect to the MySQL database on server B?

If so, how will this be done? thanks in advance

+9
source share
8 answers

its simple all of the above techniques are quite complex

Suppose you have a database on server B and a website on server A (let's say it has IP 192.234.12.1)

cpanel whitelist IP server B

and create a new user with sufficient privileges in the database (let's say this user is a test)

then create this user as test@192.234.12.1

+7
source

Yes.

In the same way that you access a local host on the same server, you change the database host to an external one. This is a configuration problem, you need to give the database user remote access to your MySQL, you also need to make sure that your firewall allows connections to the MySQL port.

Debian example: http://www.debianhelp.co.uk/remotemysql.htm

+4
source

Yes, it can be done.

Find out the IP address of server A where your scripts will be downloaded. Remember to change localhost to the IP address of server B in the mysql_connect () or mysqli_connect () method.

Now go to the server control panel B, where your database is located.

On the main page of the control panel, go to the "Databases" section and click the "Remote MYSQL" button.

Then add the IP address of server A and click on add host.

Now you can access the database on server B while your scripts are running on server A. Keep in mind that the result will be slow because it receives data from a database located on another server.

Your greeting

+3
source

Just do not specify the host name for another field to connect. Information depends on the extension used:

$mysql = mysql_connect($host, $user, $pass); $mysqli = new mysqli($host, $user, $password, $schema); $pdo = new PDO("mysql:host=$host", $user, $pass); 

Make sure the user is allowed access to the MySQL server ( CREATE USER ) and make sure that there is no firewall in this path.

+2
source

That is all you need .

(Even you can have your scripts on server A, your web server on server B and your database on server C ...)

0
source

Look at here:

http://us2.php.net/manual/en/function.mysql-connect.php

You can either pass the hostname of the server as an argument, or configure in php.ini.

0
source

I had similar problems, but here's what works for me: To connect to server B from server A, firstly, you need to allow remote hosts to access MySQL in cPanel (server B), Home → Databases → Remote MySQL, and also a whitelist of IP addresses in the firewall (this is the IP address of server B). Then the following php db connection should work.

 $db_connect = mysqli_connect("serverB.com", "dbuser", "dbpassword", "dbname"); // Evaluate the connection if (mysqli_connect_errno()) { echo mysqli_connect_error(); exit(); }else{ //successful connection echo "Yes, successful"; } 
0
source

This is an ideal solution for connecting another database from other servers.

 $dbserverName = "191.238.0.2"; $dbUsername = "lauranco_L2L"; $dbPassword = "SL92TIW5T96L"; $dbName = "lauranco_siteBits"; 
0
source

All Articles