Jump to content

NEW to MSSQL under PHP - Help!?


ksgush

Recommended Posts

Hi... I never used MySQL database that much needless to say MSSQL so, bear with me.

I have this code, and it's not working.. can anyone see anything wrong with it ??

I am not getting any errors, my page is blank and my source view is empty with standard html tags.

[code]
<?php

$myServer = "888.88.88.888";
$myUser = "888888";
$myPass = "8888888";
$myDB = "888888";

$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  //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 CartID FROM WSTOrders;";

$selected = mssql_query($query);


$numRows = mssql_num_rows($selected);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
//display the results
while($row = mssql_fetch_array($selected))
{
  echo $row["CartID"] . "";
}


?>

[/code]


Any and much help appreciated..
Link to comment
https://forums.phpfreaks.com/topic/35607-new-to-mssql-under-php-help/
Share on other sites

This should do it

<?php

$myServer = "888.88.88.888";
$myUser = "888888";
$myPass = "8888888";
$myDB = "888888";

// [color=red]$dbhandle = mssql_connect($myServer, $myUser, $myPass)  - This is where the error is. Missing semi-colon at end of line.[/color]
$dbhandle = mssql_connect($myServer, $myUser, $myPass);
  //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 CartID FROM WSTOrders;";

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

//display the results
while($row = mssql_fetch_array($selected))
{
  echo $row["CartID"] . "<br />";
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.