Sample code to connect to an MS SQL database using php

The following is sample code to connect to a MS SQL database using the php MS SQL driver.  On lines two and three, server, dbName, userName and password should be replaced with the connection settings for the applicable database.
 
Note that the driver works for SQL 2005 and higher, but not SQL 2000.
 
<?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));
}
?>
 
If you run into problems when using this code, please post in our community forum. Technical support is unable to assist with specific coding issues.