首页 > 开发 > PHP > 正文

PHP 调用MSSQL存储过程

2024-05-04 22:58:39
字体:
来源:转载
供稿:网友

存储过程如下:

create procedure test
  @tablename char(20),
  @ii char(20) output,
  @bb char(20) output
as
set nocount on
/*
if exists (select 1 from demo_table where [email protected])
  set @ii = 'yes'
else
  begin
    --raiserror('not have such a table',16,1)
    set @ii = 'no'
  end
*/
select @ii = t_id from demo_table where t_name = @tablename
if @ii is null
begin
  set @ii = 'no'
  set @bb = 'hello'
end
else
  set @bb = 'hahahahahqah'
select @ii as ii,@bb as bb

go

<?
include "conn.php";//连接数据库
/*
$query = " exec test 'demo_kh'";
$r = $db->query($query);
$result = $db->fetch_array($r);
echo $result['t_name'];
*/
  $query = "declare @ii varchar(20),@bb varchar(20)/n";
  $query .= "execute test 'demo_kh',@ii output,@bb output/n";
  $r = $db->fetch_array($db->query($query));
  echo $r['ii'].$r['bb'];
?>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表