存儲過程(procedure.sql):
create procedure hello
@yourname varchar(50) = "無名士"
as
select @yourname + ",你好!"
go
PHP3程序(procedure.php3):
<?
$server = mssql_connect("localhost","sa","") or die("無法連接數據庫服務器!");
$db = mssql_select_db("test",$server) or die("無法連接test數據庫!");
echo "<table border="1" cellspacing="0" cellpadding="0">";
echo "<tr>";
$query = "exec hello @yourname="朋友"";
$rst = mssql_query($query,$db) or die("無法執行SQL:$query");
$fields_num = mssql_num_fields($rst);
$i=0;
while($i<$fields_num){
$fields[$i] = mssql_field_name($rst,$i);
echo "<th>" . $fields[$i] . "</th>";
$i++;
}
echo "</tr>";
while ($record=mssql_fetch_array($rst)) {
echo "<tr>";
$i=0;
while($i<$fields_num){
$value = $record[$fields][$i]];
if($value=="")
echo "<td> </td>";
else
echo "<td>" . $value . "</td>";
$i++;
}
echo "</tr>";
}
mssql_free_result($rst);
echo "</table>";
mssql_close($server) or die("無法與數據庫服務器斷開連接!");
?>