PHP中的SQL Server存储过程输出参数 [英] SQL Server Stored Procedure Output Params in PHP

查看:146
本文介绍了PHP中的SQL Server存储过程输出参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PHP从SQL Server运行存储过程的帮助. PHP在Unix/Linux服务器上运行.我们无法使OUTPUT变量返回PHP.以下是PHP代码:

I need help running a stored procedure from SQL Server in PHP. PHP is running on a Unix/Linux server. We cannot get OUTPUT variables to return in PHP. The following is the PHP code:

$conn = mssql_connect('server', 'user', 'pass');
    mssql_select_db('db', $conn);

    $procedure = mssql_init('usp_StoredProc', $conn);

    $tmpVar1 = 'value';
    $tmpVar2 = 'value2';

    $outVar1 = '';
    $outVar2 = '';

    mssql_bind($procedure, "@var1", $tmpVar1, SQLVARCHAR, false, false);
    mssql_bind($procedure, "@var2", $tmpVar2, SQLVARCHAR, false, false);

    mssql_bind($procedure, "@outVar1", $outVar1, SQLVARCHAR, true);
    mssql_bind($procedure, "@outVar2", $outVar2, SQLVARCHAR, true);

    mssql_execute($procedure,$conn);

    print($outVar1);
    print($outVar2);

存储过程如下:

    SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[usp_StoredProc]
(
    @var1 as varchar(36), 
    @var2 as varchar(10), 
    @outVar1 varchar(36) OUTPUT, 
    @outVar2 varchar(36) OUTPUT 
)
as
  select distinct 
    @outVar1 = row1, 
    @outVar2 = row2
  from table1
  where column1 = @var1
    and column2 = @var2

谁能告诉我为什么不填充$ outVar1和$ outVar2?非常感谢您的帮助!

Can anyone tell me why $outVar1 and $outVar2 are not being populated? Thanks a lot for any help!

推荐答案

根据此有关PHP错误的页面,您必须(强调我的意思):

According to this page on PHP bugs, you have to (emphasis mine):

为每个呼叫mssql_next_result() SP返回的结果集.这 处理多个结果的方式.

call mssql_next_result() for each result set returned by the SP. This way you can handle multiple results.

mssql_next_result()返回false时 您将有权访问输出 参数和返回值.

When mssql_next_result() returns false you will have access to output parameters and return value.

这篇关于PHP中的SQL Server存储过程输出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆