Error while connecting with SQL Server

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 7
Joined: Wed Sep 01, 2010 2:24 am

Sun Jul 03, 2011 9:54 pm


I am not able to connect to SQLServer database hosted on some other machine.
I am using the following code to do this:

$myServer = "";
$myUser = "sa";
$myPass = "test123";
$myDB = "test_DBSchema";

//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 count(*) from test";
//Name, Address, City

//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

Please suggest me.

Manoj Singh

User avatar
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Tue Jul 05, 2011 7:01 am

Any errors ?

Hard to help, with out any debugging!

Post Reply