Reputation: 1
How to make db connection my php scripts on server A and connect to the MySQL database on server B?
Upvotes: 0
Views: 141
Reputation: 3593
You need to do few steps:
Upvotes: 1
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