Sample PHP MSSQL connection script
« on: December 05, 2008, 10:16:16 PM »
As of PHP 5.3, default MSSQL driver is no longer available in PHP. As an alternative, you can use PDO_SQLSRV Driver to connect to your MSSQL database. Before you use this extension, you will have to enable it from your PHP configuration. You can refer the following URL for sample code:

For native php_msql diver, the following script should work:

Code: [Select]
$User "your_name";
$Pass "your_password";
$DB "examples";

//connection to the database
$dbconn mssql_connect($Server$User$Pass)
  or die(
"Couldn't connect to SQL Server on $Server");

//select a database to work with
$selected mssql_select_db($DB$dbconn)
  or die(
"Couldn't open database $myDB");

//declare the SQL statement that will query the database
$query "SELECT name from test ";

//execute the SQL query and return records
$result mssql_query($query);

$numRows mssql_num_rows($result);
"<h1>" $numRows " Row" . ($numRows == "" "s") . " Returned </h1>";

//display the results
while($row mssql_fetch_array($result))
"<br>" $row["name"];
//close the connection

If you are using PHP MSSQL driver, you can refer Sample PHP MSSQL connection script using PHP MSSQL driver.
« Last Edit: July 15, 2020, 04:39:34 PM by Kailash »