What are the common issues when accessing a remote database server in PHP?

Common issues when accessing a remote database server in PHP include connection timeouts, incorrect credentials, and firewall restrictions. To solve these issues, ensure that the database server is reachable from the PHP server, double-check the database credentials, and configure the firewall to allow connections from the PHP server.

<?php
$servername = "remote_server";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

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