我需要帮助在PHP中运行SQL Server的存储过程。PHP运行在Unix/Linux服务器上。我们无法在PHP中获取输出变量。以下是PHP代码:
$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没有被填充吗?非常感谢任何帮助!