The official guide for connecting to SQL Server using the PHP driver from Microsoft seems pretty straightforward, so I copied the text for the most part:
$server = "serverlocation\prod";
$database = array( "Database"=>"temp");
$conn = sqlsrv_connect($server, $database);
echo "<pre>";
if ( $conn ) {
echo "Connection established";
} else {
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
When I run the code, I got the following error:
Connection could not be established.
Array
(
[0] => Array
(
[0] => 28000
[SQLSTATE] => 28000
[1] => 18456
[code] => 18456
[2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user '*****DOMAIN\MY_MACHINE_NAME*****'.
[message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user '*****DOMAIN\MY_MACHINE_NAME*****'.
)
I am running this code on the machine name that is listed in the error message, which is a Windows machine, but the machine name listed is NOT the user account under which I am logged in. The user account under which I am logged in has rights to this database, (and I can connect to it using MS SQL Server Managment Studio just fine...) but when I try to connect using this script, it displays my machine name instead of my user account.
What am I doing wrong?