MySQL Forums
Forum List  »  Stored Procedures

Unable to get OUT parameter in PHP
Posted by: Galen Mayfield
Date: January 02, 2009 11:17AM

All,

Hi. I've read through this forum, a few web sites, and a couple books, so I'm sure I'm probably just overlooking something. In that case, let me apologize in advance for my question. However, I've hit a bit of snag and am hoping you can help me out. I'm an experienced ASP programmer, but new to PHP and MySQL.

I have a stored procedure that, when I call it from the MySQL query browser, works just fine. However, when I call it from PHP, I get nothing back. This leads me to believe that I'm calling it from PHP in the wrong way. The Code:

SP:
-----------

DELIMITER $$

DROP PROCEDURE IF EXISTS `litrunner`.`authenticateUser` $$
CREATE DEFINER=`xx@xx` PROCEDURE `authenticateUser`(IN useremail VARCHAR(100), IN userpassword VARCHAR(40), OUT AUTHENTICATIONCODE INT)
BEGIN

DECLARE numMatches INT DEFAULT 0;


SET numMatches = (SELECT COUNT(*) FROM vwUsers WHERE email = useremail AND password = userpassword);

CASE numMatches


-- AUTHENTICATION CODES

-- 0 = NO MATCH
-- 1 = 1 MATCH FOUND
-- 2 = MULTIPLE MATCHES FOUND
-- 3 = UNDEFINED


WHEN numMatches<0 THEN
SET AUTHENTICATIONCODE = 3;
WHEN 0 THEN
SET AUTHENTICATIONCODE = 0;
WHEN 1 THEN
SET AUTHENTICATIONCODE = 1;
WHEN numMatches>1 THEN
SET AUTHENTICATIONCODE = 2;
ELSE
SET AUTHENTICATIONCODE = 3;

END CASE;

END $$

DELIMITER ;
----

Here ends the SP code. When I call this from the query browser like so:

call authenticateUser('literal@literal.com', 'anotherLiteral', @AUTHENTICATIONCODE);
SELECT @AUTHENTICATIONCODE;

I get back the appropriate AUTHENTICATIONCODE.


PHP snippet:
-----
$useremail = $_POST['email'];
$userpassword = $_POST['password'];

$db_conn = new mysqli($host, $dbusername, $dbpassword, $db);

if (mysqli_connect_errno()) {
echo 'Login Failed. Your username and/or password are incorrect.';
exit();
}

$authCode = "";

$authenticationResultSet = $db_conn->multi_query("call authenticateUser($useremail, $userpassword, @AUTHENTICATIONCODE);SELECT @AUTHENTICATIONCODE");
echo "dudedafdfs:";
if ($authenticationResultSet) {
echo "dudes:";
$results = 0;
do {

if ($result = $db_conn->store_result()) {

while($row = $result->fetch->fetch_row()) {
foreach($row as $cell) {
$authCode = $cell;
echo "dude: ".$cell."<BR><BR>";
}
}
$result->close();
}
} while($db_conn->next_result());
}
----
Here ends the PHP snippet. The condition if ($authenticationResultSet) is not coming out true, so I'm guessing there's something wrong w/ this statement:

$authenticationResultSet = $db_conn->multi_query("call authenticateUser($useremail, $userpassword, @AUTHENTICATIONCODE);SELECT @AUTHENTICATIONCODE");

Any guidance you can provide will be much appreciated.

Thanks in advance.

Options: ReplyQuote


Subject
Views
Written By
Posted
Unable to get OUT parameter in PHP
5533
January 02, 2009 11:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.