Home > php教程 > php手册 > PHP基于ADODB调用MSSQL存储过程

PHP基于ADODB调用MSSQL存储过程

WBOY
Release: 2016-06-13 11:38:56
Original
869 people have browsed it

前几天弄PHP调用MSSQL存储过程,搞了许久,网上资料也少之又少(特别是基于ADODB的)。
那在这我就举个基于ADODB调用MSSQL存储过程的例子吧,希望对人有所帮助。
/*
  Test out params - works in PHP 4.2.3 and 4.3.3 and 4.3.8 but not 4.3.0:
 
   CREATE PROCEDURE at_date_interval
    @days INTEGER,
    @start VARCHAR(20) OUT,
    @end VARCHAR(20) OUT 
   AS
   BEGIN
    set @start = CONVERT(VARCHAR(20), getdate(), 101)
    set @end =CONVERT(VARCHAR(20), dateadd(day, @days, getdate()), 101 )
   END
   GO
  */
  $db->debug=1;
  $stmt = $db->PrepareSP('at_date_interval');
  $days = 10;
  $begin_date = '';
  $end_date = '';
  $db->InParameter($stmt,$days,'days', 4, SQLINT4);     //这里97xxoo是In参数
  $db->OutParameter($stmt,$begin_date,'start', 20, SQLVARCHAR ); //这是存储过程返 回值,可直接访问$begin_date所得到。
  $db->OutParameter($stmt,$end_date,'end', 20, SQLVARCHAR ); //同上
  $db->Execute($stmt);

  echo $begin_date;
  echo $end_date;

这样就OK了,这简单的例子相信都能看得懂,其他的原理也是相同的。
在这里还要注意的是:$begin_date ,$end_date 一样要先赋个空值,否则结果取不到值。这就是害我搞了N久的原因了。

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template