Priti Soam
Priti Soam

Reputation: 1

How to make db connection in php of on other server A to sever B

How to make db connection my php scripts on server A and connect to the MySQL database on server B?

Upvotes: 0

Views: 141

Answers (2)

Naveed Ramzan
Naveed Ramzan

Reputation: 3593

You need to do few steps:

  • On server B, Make enable remote access to database
  • On server A, db connection file make host => IP of server b

Upvotes: 1

Sumit Wadhwa
Sumit Wadhwa

Reputation: 3217

$conn = new mysqli($servername, $username, $password);

This should work just fine.

$conn = new mysqli(223.122.212.2:90, 'root', 'root');

where 223.122.212.2 is ip to server B, running mysql server and listening on port 90. Make sure that server B is running mysql on port 90 (or any other port you'd like) and firewall, if any, configured in a way that allows remote connection.

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

Upvotes: 1

Related Questions