Sample code to connect to an MS SQL database using php

Below is a simple PHP script to demonstrate how to connect to a MS SQL database using the php MS SQL driver.

<?php
$serverName = "serverName";
$connectionInfo = array( "Database"=>"databaseName", "UID"=>"userName", "PWD"=>"password", "TrustServerCertificate"=>True);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>