Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all articles
Browse latest Browse all 391

Getting scalar results from SQL Server Stored Procedure using PHP and sqlsrv functions

$
0
0

I have created a Stored Procedure in MS SQL 2014 which is given a username and password and returns 0: Success; 1: Username not found; or 2: Password doesn't match.

CREATE PROCEDURE authConfirmUserPass
	@username varchar(30),
	@password varchar(32),
	@resultValue int OUTPUT
AS
BEGIN
	SET NOCOUNT ON;
	-- Much processing left out
	SET @resultValue = 1
	SELECT @resultValue
END
GO

When I test this in SQL Server Management Studio, it seems to work fine

DECLARE	@resultValue int
DECLARE @password varchar(32)
EXEC [dbo].[authConfirmUserPass] N'badUserName', N'badPassword', @resultValue OUTPUT
SELECT	'Return Value' = @resultValue
GO

However, when I try to get the return value inside of PHP, the value of my output variable never seems to change:

$resultValue = -10;
$qry = "{call authConfirmUserPass( ?, ?)}";
$params = array(
	array($username, SQLSRV_PHPTYPE_STRING, SQLSRV_PARAM_IN),
	array($password, SQLSRV_PHPTYPE_STRING, SQLSRV_PARAM_IN),
	array($resultValue, SQLSRV_PHPTYPE_INT, SQLSRV_PARAM_OUT)
	);
$stmt = sqlsrv_query($this->connection, $qry, $params);
echo "<p>Result is: $resultValue</p>";
sqlsrv_next_result($stmt);
echo "<p>Next Result is: $resultValue</p>";

Calling the stored procedure does not seem to ever change the value of $resultValue. I always get -10.

Any ideas what I am doing wrong? I have spent hours searching and reading for answers online, but to no avail.




Viewing all articles
Browse latest Browse all 391

Trending Articles