Faqts : Business : Programming : Shopping For You : PHP : Database Backed Sites : MSSQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

74 of 88 people (84%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

I need an example of PHP code using MSSQL database? I have installed PHP and MSSQL on my server.Both of them are working fine
Platform win2000Prof , MSSQL7.0, php4.2.2 , Apache WebServer and when I try to connect I have got me

Sep 8th, 2002 05:42
Pierre Koomen, narayanadas vakamudi, ilya osipov, www.php.net


<?php 


$hostname = "localhost"; 
$username = "login"; 
$password = "password"; 
$dbName = "database"; 

MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO 
RESPOND."); 
mssql_select_db($dbName) or DIE("Table unavailable"); 

$query = "SELECT * FROM users"; 

$result = MSSQL_QUERY($query); 

$number = MSSQL_NUM_ROWS($result); 

$i=0; 

if ($number == 0) : 
print "No data?"; 
elseif ($number > 0) : 
print "Data:
"; 
while ($i < $number) : 
$name = mssql_result($result,$i,"Name"); 
print $name; 
print "
"; 
$i++; 
endwhile; 
endif; 
?>