文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用PHP3调用MicrosoftSQLServer的存储过程

用PHP3调用MicrosoftSQLServer的存储过程

时间:2007-02-17  来源:PHP爱好者

存储过程(procedure.sql):
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  create procedure hello
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   @yourname varchar(50) = "无名士"
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  as
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  select @yourname + ",你好!"
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  go
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr

www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
PHP3程序(procedure.php3):
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  <?
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  $server = mssql_connect("localhost","sa","") or die("无法连接数据库服务器!");
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  $db = mssql_select_db("test",$server) or die("无法连接test数据库!");
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr

www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  echo "<table border="1" cellspacing="0" cellpadding="0">";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  echo "<tr>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr

www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  $query = "exec hello @yourname="朋友"";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  $rst = mssql_query($query,$db) or die("无法执行SQL:$query");
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  $fields_num = mssql_num_fields($rst);
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  $i=0;
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  while($i<$fields_num){
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   $fields[$i] = mssql_field_name($rst,$i);
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   echo "<th>" . $fields[$i] . "</th>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   $i++;
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  }
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  echo "</tr>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  while ($record=mssql_fetch_array($rst)) {
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   echo "<tr>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   $i=0;
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   while($i<$fields_num){
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   $value = $record[$fields[$i]];
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   if($value=="")
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   echo "<td>?/td>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   else
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   echo "<td>" . $value . "</td>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   $i++;
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   }
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
   echo "</tr>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  }
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  mssql_free_result($rst);
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr

www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  echo "</table>";
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  mssql_close($server) or die("无法与数据库服务器断开连接!");
www.chinaitpower.com6feOvQl78G0MipkDHpMoh6dwr
  ?>
非常全面的一个php技术网站,php 爱好者站 http://www.phpfans.net 有相当丰富的文章和源代码.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载