Connecting via PHP

The following example shows how to connect to the SQL Server via PHP.


<?php
$myServer = "mssql-xxxxx-0.cloudclusters.net,xxxxx";
$myUser = "your database user name";
$myPass = "your password";
$myDB = "your database name";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

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

//declare the SQL statement that will query the database
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'";

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

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

//display the results
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?>
Copyright © 2021 Cloud Clusters Inc. all right reserved,powered by GitbookRevised on 09/29/2021

results matching ""

    No results matching ""