Sqlsrv kode
HejVille i lave denne kode anderledes?
function Authentication() {
session_start();
if (empty($_SESSION['username'])) {
$serverName = "localhost"; //serverName\instanceName
$connectionInfo = array( "Database"=>"database", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if($conn === false) {
echo 'Der kunne ikke oprettes forbindelse til databasen!';
die();
}
list($domain, $username) = explode('\\','nbadm\ssf');
$sql = "SELECT Id, PersonId, Username, Firstname, Lastname FROM Users WHERE Domain = ? AND Username = ? AND Active = 1";
$params = array($domain, $username);
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query($conn, $sql, $params, $options);
$row_count = sqlsrv_num_rows($stmt);
if ($row_count > 0) {
$result = sqlsrv_fetch_array($stmt);
$_SESSION['id'] = $result['Id'];
$_SESSION['personid'] = $result['PersonId'];
$_SESSION['username'] = $result['Username'];
$_SESSION['firstname'] = $result['Firstname'];
$_SESSION['lastname'] = $result['Lastname'];
} else {
echo HTML('AccessDenied');
die();
}
}
}