Connecting to SQL Server using PHP

The following lines of code can be used to connect to the SQL Server. Please note you can only connect to SQL Server from PHP code on stuiis.cms.gre.ac.uk web server, and NOT from stuweb.cms.gre.ac.uk:

$serverName = "SQL-SERVER"; 
$connectionInfo = array( "Database"=>"username");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

$rs = $conn->Execute("SELECT * FROM account"); 

while (!$rs->EOF) { 
$fv = $rs->Fields("account_description"); 
echo "ID: ".$fv->value."\n"; 
$rs->MoveNext(); 
} 

$rs->Close();

Comments are closed.