php调用SQLServer的存储过程
时间:2007-02-17 来源:PHP爱好者
存储过程(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 "";
echo " ";
$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 " " . $fields[$i] . " ";
$i++;
}
echo "
";
while ($record=mssql_fetch_array($rst)) {
echo " ";
$i=0;
while($i<$fields_num){
$value = $record[$fields[$i]];
if($value=="")
echo " ";
else
echo " " . $value . " ";
$i++;
}
echo "
";
}
mssql_free_result($rst);
echo " ";
mssql_close($server) or die("无法与数据库服务器断开连接!");
?>
php爱好者站 http://www.phpfans.net dreamweaver|flash|fireworks|photoshop.
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 "";
echo " ";
$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 " " . $fields[$i] . " ";
$i++;
}
echo "
";
while ($record=mssql_fetch_array($rst)) {
echo " ";
$i=0;
while($i<$fields_num){
$value = $record[$fields[$i]];
if($value=="")
echo " ";
else
echo " " . $value . " ";
$i++;
}
echo "
";
}
mssql_free_result($rst);
echo " ";
mssql_close($server) or die("无法与数据库服务器断开连接!");
?>
php爱好者站 http://www.phpfans.net dreamweaver|flash|fireworks|photoshop.
相关阅读 更多 +