php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22294 Output parameter is not populated
Submitted: 2003-02-19 04:36 UTC Modified: 2003-05-20 18:19 UTC
Votes:7
Avg. Score:4.6 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:6 (100.0%)
From: rajesh dot gala at cgi dot com Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.2-dev OS: win32
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rajesh dot gala at cgi dot com
New email:
PHP Version: OS:

 

 [2003-02-19 04:36 UTC] rajesh dot gala at cgi dot com
I use MS SQL 2000.

I have a simple Stored procedure to be executed. the code is as below

the Stored proc is 
Create  PROCEDURE [AuthLoginUser]
	@LoginUser 	CHAR(10),
	@Password 	CHAR(32),
	@ReturnVal 	INT OUTPUT

AS

BEGIN

	SELECT	@ReturnVal = count(*)
	FROM 	[User]	USR
	WHERE	USR.[User ID]	= @LoginUser
	AND     USR.[Password]  = @Password		
	AND     USR.[Status]='A'
	
END

The php code is as below

$stmt = mssql_init("AuthLoginUser", $conn);

$LoginUser=$strRegisteredUsername ;
$Password=$strRegisteredPassword ;

mssql_bind($stmt,"@LoginUser",$LoginUser,SQLVARCHAR);
mssql_bind($stmt,"@Password",$Password,SQLVARCHAR);
mssql_bind($stmt,"@ReturnVal",$ReturnVal,SQLINT4,True);

$result=mssql_execute($stmt);			

echo '<br><b>Return Value'.$ReturnVal.'</b>';

The problem is that variable $ReturnVal does not get populated

I executed the Stored procedure in the query analyser and I get values for the same.

Thanks,
Rajesh

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-06 04:39 UTC] php at centaur dot mailshel dot com
Output parameters seem to be populated after all result set are fetched using mssql_next_result(). However, mssql_execute seems to only return a valid result set resource on 'SELECT' queries, and not 'SELECT @param = expr' queries. The $result in a similar case is just 1.
 [2003-03-06 04:44 UTC] php at centaur dot mailshell dot com
In addition to my previous comment:
Windows XP SP1
MSSQL 2000
PHP Version => 4.3.2-dev
Build Date => Feb 26 2003 02:23:31
Server API => Apache 2.0 Filter
 [2003-03-06 23:08 UTC] rajesh dot gala at cgi dot com
This too does not Work

PHPCode

$UserID = 'ADMIN';
$conn = mssql_connect("SERVER", "UID", "PASS"); 
mssql_select_db("DBANAME",$conn); 
$stmt = mssql_init("SELUser",$conn); 
mssql_bind($stmt,"@UserID",$UserID,SQLCHAR,false); mssql_bind($stmt,"@ReturnVal",$ReturnVal,SQLINT4,True); $result=mssql_execute($stmt); 
mssql_fetch_array($result); 
echo $ReturnVal; 

Stored Procedure

CREATE     PROCEDURE [SELUser]
	@UserID	CHAR(10),
	@ReturnVal INT OUTPUT
AS
BEGIN
	SELECT	*
	FROM 	[User]	USR
	WHERE	USR.[User ID]	= @UserID
	SET @ReturnVal=@@ROWCOUNT
END

I get the data in the resultset but not in the Output paramenter. I have used the Output parameter in different ways across the application. How can we get the output parameter populated.

Thanks
 [2003-03-06 23:12 UTC] rajesh dot gala at cgi dot com
The version of PHP is use is 4.3.1 windows binary downloaded from the php.net site. The zip file date is 18-Feb-2003.
SQL Server 2000
OS Win 2000
Webserver Apache 4.0.44
 [2003-03-06 23:19 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

There have been some fixes for mssql stuff in it..


 [2003-03-06 23:20 UTC] sniper@php.net
forget my last comment, I didn't notice that you already
had tried the snapshot..

 [2003-04-10 04:43 UTC] arnarb at oddi dot is
The documentation states that output variables have to be passed by reference into mssql_bind. Like this

mssql_bind($stmt,"@ReturnVal",&$ReturnVal,SQLINT4,True);

Also, the documentation also notes that if a stored procedure returns multiple result sets, the output parameters will _not_ be available until mssql_next_result has been called for the last result-set.

Does this have any effect on your test cases?

--Arnar
 [2003-04-22 06:45 UTC] rajesh dot gala at cgi dot com
mssql_bind($stmt,"@ReturnVal",&$ReturnVal,SQLINT4,True);

does not work.
 [2003-05-20 18:19 UTC] fmk@php.net
I have just testet this sample with the current CVS version.

This is my exact test code

<?php

if (!extension_loaded("mssql")) {
	dl("php_mssql.dll");
}

$conn = mssql_connect("asterix","web","webuser");

$stmt = mssql_init("AuthLoginUser", $conn);

$LoginUser = "frank";
$Password = "frank123";

mssql_bind($stmt,"@LoginUser",$LoginUser,SQLVARCHAR);
mssql_bind($stmt,"@Password",$Password,SQLVARCHAR);
mssql_bind($stmt,"@ReturnVal",&$ReturnVal,SQLINT4,True);

$result=mssql_execute($stmt);			

echo '<br><b>Return Value '.$ReturnVal.'</b>';

mssql_close($conn);

?>


And this is my output

Return Value 1

There is no problems with return values as far as I can telle.

mssql_bind($stmt,"@ReturnVal",&$ReturnVal,SQLINT4,True);
and
mssql_bind($stmt,"@ReturnVal",$ReturnVal,SQLINT4,True);

both works as the third parameter is forced to be BYREF.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 19:01:31 2024 UTC