Hello All,
In order to connect MS SQL server with front end as PHP one need to use below mentioned sample connection code:
<?php
$myServer = "localhost";
$myUser = "database_username";
$myPass = "User_password";
$myDB = "Database_Name";
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
mssql_close($dbhandle);
?>
That’s it!
Thanks,
Shane G.
AccuWebHosting.Com
In order to connect MS SQL server with front end as PHP one need to use below mentioned sample connection code:
<?php
$myServer = "localhost";
$myUser = "database_username";
$myPass = "User_password";
$myDB = "Database_Name";
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
mssql_close($dbhandle);
?>
That’s it!
Thanks,
Shane G.
AccuWebHosting.Com
Comment