I decided to use the stored procedures in MySQL. I am able to retrieve only one row value in OUT paramater, but when the returned result contains more than one row, I get nothing!
Please see the simple code below for stored procedure which I add it to phpmyadmin direct:
DELIMITER ;;
DROP PROCEDURE IF EXISTS SelectContacts ;;
CREATE PROCEDURE SelectContacts(OUT mobileNumber VARCHAR(255))
BEGIN
SELECT accounts.mobile_number FROM accounts WHERE accounts.account_id = 1 OR accounts.account_id=2 INTO mobileNumber;
END ;;
/////////
Now to call the procedure from PHP:
/////////////////////////////////////////
$result = mysql_query("CALL SelectContacts(@mobileNumber)");
while($row = mysql_fetch_assoc($result))
print_r($row); /// no output because the result has more than one value
Now: when the query returns more than one row like below, I get nothing
SELECT accounts.mobile_number FROM accounts WHERE accounts.account_id = 1 OR accounts.account_id=2 INTO mobileNumber; #no output here#
But: when the query returns only one row like below, I get correct result
SELECT accounts.mobile_number FROM accounts WHERE accounts.account_id = 1 INTO mobileNumber; #here I got output#
Can you please advise how to retrieve more than one value in OUT parameter using stored procedure? using normal query is working okey with me but unable to do that with stored procedure.
Mysql version is 5++, PHP 5
Please advise.
Thanks.