Home >php教程 >php手册 >例子:用PHP3调用Microsoft SQL Server的存储过程

例子:用PHP3调用Microsoft SQL Server的存储过程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-22 17:21:34807browse

存储过程(procedure.sql):

  create procedure hello

      @yourname varchar(50) = "无名士"

  as

  select @yourname + ",你好!"

  go

PHP3程序(procedure.php3):

<?php
  $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("无法与数据库服务器断开连接!");
?>


永久地址:

转载随意~请带上教程地址吧^^

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn