What are some potential reasons for the error message "Unable to connect to server" when using mssql_connect in PHP?

The error message "Unable to connect to server" when using mssql_connect in PHP could be due to various reasons such as incorrect server credentials, server connectivity issues, firewall restrictions, or the MSSQL extension not being enabled in PHP. To solve this issue, double-check the server credentials, ensure proper network connectivity, verify firewall settings, and enable the MSSQL extension in PHP configuration.

$server = 'localhost';
$username = 'username';
$password = 'password';
$database = 'database_name';

$conn = mssql_connect($server, $username, $password);

if (!$conn) {
    die('Unable to connect to server: ' . mssql_get_last_message());
} else {
    echo 'Connected to server successfully!';
}