PHP - Jobba med databaser

Webbutveckling / PHP

Anslut till MSSQL-databas

Spar exempelkoden nedan i en fil med filändelsen .php

Exempelkod:

<?php
$serverName = "PCNAME\SQLEXPRESS"; //serverName\instanceName

// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.

$connectionInfo = array("Database" => "db_name");
$conn = sqlsrv_connect($serverName, $connectionInfo);

if($conn){
echo "Connected to database";
} else {
echo "Connection to database could not be established";
die(print_r(sqlsrv_errors(), true));
}

sqlsrv_close($conn);
?>