|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-01-18 08:32 UTC] coldgrass at gmail dot com
Description:
------------
environment:php5.2.5,mssql server 2005
I can't retrieve stored procedure return values
Reproduce code:
---------------
$sth = $DB->prepare('exec proc_getDeviceNumByHdType :inpara,:usetable,:num');
$sth->bindParam(":inpara", $para, PDO::PARAM_STR);
$sth->bindParam(":usetable", $paraTable, PDO::PARAM_STR);
$sth->bindParam(":num", $return, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,1);
$sth->execute();
create procedure [dbo].[proc_getDeviceNumByHdType]
@hdtype as varchar(256),
@usetable varchar(50),
@num int output
AS
begin
DECLARE @sql Nvarchar(1000)
SET @sql = N'SELECT @num=COUNT(*) from '+CAST(@usetable AS NVARCHAR(50))
EXECUTE sp_executesql @sql,N'@num int output',@num output
end
Expected result:
----------------
after call procedure ,there is no return value;
Actual result:
--------------
should have a value;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 14 11:00:01 2025 UTC |
This is happening for me in 5.3.1., using Pdo_Dblib. Trying to call a stored procedure on SQL Server 2005 server. Cannot retrieve a value. PHP version 5.3.1 Using Pdo_Dblib Linux: 2.6.24-24-server SMP x86_64 GNU/Linux PHP Code: ---------------------------- /** SNIP. Set up a valid $db here! **/ $return_value = 999; $sth = $db->prepare("EXEC dbo.opsp_Test ?"); $sth->bindParam(1, $return_value, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 4); $sth->execute(); echo "$return_value\n"; Return value ALWAYS comes back as 999, no matter what variations I try in bindParam call. Here's my Stored Procedure: --------------------------- CREATE PROCEDURE opsp_Test @TheOutputValue int OUTPUT AS BEGIN SET @TheOutputValue = 11 ENDI can confirm that the same issue is present in version 5.3.3. The value of $result in the following code snippet will not be changed after the SP is run (even though the procedure returns a value when run from SQL Server Management Studio / freetds / or via mssql_query() $result = ""; $stmt = $pdo->prepare("exec sp_nextSerialNumGet ?") $stmt->bindParam(8, $result, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 25); $stmt->execute(); echo $result; // empty OR $execArray = array(':result' => ""); $stmt = $pdo->prepare("call sp_nextSerialNumGet (:result)"); $stmt->execute($execArray); echo $stmt->fetch(); //empty, var_dump($stmt->fetchAll()) show array (0) {}