<?php
$serverName = "serverNamesqlexpress"; //serverNameinstanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"dbName");
$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));
}
?>
This is an update to a note I wrote earlier concerning how to set multiple attributes when you create you PDO connection string.
You can put all the attributes you want in an associative array and pass that array as the fourth parameter in your connection string. So it goes like this:
<?php
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_EMPTY_STRING
];
// Now you create your connection string
try {
// Then pass the options as the last parameter in the connection string
$connection = new PDO("mysql:host=$host; dbname=$dbname", $user, $password, $options);
// That's how you can set multiple attributes
} catch(PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
?>