What are common issues when trying to establish a database connection to MS-SQL using PHP?

Common issues when trying to establish a database connection to MS-SQL using PHP include incorrect server credentials, missing SQL Server drivers in PHP, and firewall restrictions blocking the connection. To solve these issues, ensure the server credentials are correct, install the necessary SQL Server drivers in PHP, and configure the firewall to allow the connection.

<?php
$serverName = "your_server_name";
$connectionOptions = array(
    "Database" => "your_database_name",
    "Uid" => "your_username",
    "PWD" => "your_password"
);

$conn = sqlsrv_connect($serverName, $connectionOptions);

if($conn) {
    echo "Connection established.";
} else {
    echo "Connection could not be established.";
}
?>