php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43887 mssql2005 PROCEDURE PDO::PARAM_INPUT_OUTPUT
Submitted: 2008-01-18 08:32 UTC Modified: 2009-05-03 01:00 UTC
Votes:25
Avg. Score:4.8 ± 0.6
Reproduced:22 of 22 (100.0%)
Same Version:4 (18.2%)
Same OS:10 (45.5%)
From: coldgrass at gmail dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: coldgrass at gmail dot com
New email:
PHP Version: OS:

 

 [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;

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-30 08:56 UTC] miha dot vrhovnik at domenca dot si
Can confirm this on Linux.

PHP 5.2.6, connecting to MSSQL 2000 via freetds 0.82RC4

Guys please fix that I had to revert back to mssql_* functions for calling stored procedures. So Now half of project uses PDO the other half the old functional style...
 [2008-11-26 22:37 UTC] aventurella at gmail dot com
I can confrim this on MySQL and PostgreSQL as well.  No PARAM_INPUT_OUTPUT values get bound through PDO when running a stored 
procedure.

http://bugs.php.net/bug.php?id=46657
 [2008-11-26 22:39 UTC] aventurella at gmail dot com
forgot my php/OS version: 5.2.6 on OS X 10.5.5
 [2009-04-25 14:54 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-12-22 21:53 UTC] david dot wright at opticsplanet dot com
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
END
 [2011-07-30 11:24 UTC] eugene dot trotsan at gmail dot com
I 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) {}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 14 04:01:27 2025 UTC