php调用ms sql存储过程。。。

发表于:2007-06-21来源:作者:点击数: 标签:
? php $hostname = tszzp; $dbuser = sa; $dbpasswd = ; $id = ms sql _connect($hostname,$dbuser,$dbpasswd) or die(无法连接 数据库 服务器 !); //printf(%dBR\n, $id); $db = mssql_select_db(stock,$id) or die(无法连接stock数据库!); $stockcode=60

   
   <?php
$hostname = "tszzp";
$dbuser = "sa";
$dbpasswd = "";

$id = mssql_connect($hostname,$dbuser,$dbpasswd) or die("无法连接数据库服务器!");

//printf("%d<BR>\n", $id);
$db = mssql_select_db("stock",$id) or die("无法连接stock数据库!");
$stockcode='600600';
$id = 0;
$msg = 0;
//printf("%d<BR>\n", $db);
//$query = "exec sp_test @code='600028',@id=0,@msg='000000'";
$query = "declare @result int, @id int, @msg varchar(20)\n";
$query.="exec @result=sp_test\n";
$query.="\"$stockcode\",\n";
$query.="@id output,\n";
$query.="@msg output;\n";
$query.="select @result result, @id id, @msg msg";
/*$query = "declare @result int, @id int, @msg varchar(20)\n";
$query.="exec @result=sp_test\n";
$query.="\"$stockcode\",\n";
$query.="@id output,\n";
$query.="@msg output;\n";
$query.="select @result result, @id id, @msg msg";
*///$query = "update test set stockname='2test' where stockcode='600028'";
//$query = "insert into test(stockcode,stockname,id) values ('600028','test',13)";
//$query = "select * from test where stockcode='600028'";
//$query = "select 0 where 1=0 ";
$rresult = mssql_query($query) or die("无法执行SQL:$query");
$arr = mssql_fetch_array($rresult);
print $result;
print "<br>\n";
printf("%d, %d, %s<br>\n", $arr[result], $arr[id], $arr[msg]);
printf("%d, %s<br>\n", $id, $msg);
//$stock = mssql_fetch_array($result);
//$name = $stock[id];
//print $name;
//print "abc";

?>

原文转自:http://www.ltesting.net