It is currently Tue May 21, 2013 4:42 pm

All times are UTC


You can access below Applications



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: how to retrieve records using php and mssql?
PostPosted: Wed Dec 29, 2010 12:00 pm 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
Hi

how to retrieve records using php and mssql?

mssql_query

Quote:
mixed mssql_query ( string $query , resource $link_identifier , int $batch_size = 0)


send query to the sql server to the associated database , return true if success or false on error.

if link_identifier is not present means assumed the last opened link .

the following sample is used to retrieve records from database and display
Code:

  <?php

$myServer 
= ".\SQLEXPRESS";
$myUser = "sa";
$myPass = "test";
$myDB = "testdb";

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

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

//declare the SQL statement that will query the database
$query = "SELECT empid,empname ";
$query .= "FROM test";


//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
echo "<ul>";

while(
$row = mssql_fetch_array($result))
{

  echo "<li>" . $row["empid"] . $row["empname"] . $row["year"] . "</li>";
}
echo "</ul>";
//close the connection
mssql_close($dbhandle);
?> 
 
Share |

_________________
Thanks,
A.ThangaSornam,

QualityPointTechnologies,
Ottapidaram.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron