Is there a way to retrieve Out Parameter and a Result Set using PHP and MySQL.
Take for example the below scenario:
CREATE TABLE `test`.`users` (
`users_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(100) NOT NULL,
`last_name` VARCHAR(100) NOT NULL,
PRIMARY KEY (`users_id`)
)
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`get_user`$$
CREATE PROCEDURE `test`.`get_user`
(
IN userId INT,
OUT firstName VARCHAR(100),
OUT lastName VARCHAR(100)
)
BEGIN
SELECT first_name, last_name
INTO firstName, lastName
FROM users
WHERE users_id = userId;
SELECT Roles.* FROM Roles INNER JOIN users ON users.users_id = Roles.Users WHERE users.users_id = userId; END $$ DELIMITER ;
Given the above scenario, the stored procedure has 2 sets of results. 1. The first_name and last_name as Out Parameters 2. A result set for executing the Select Statement with the join.
I can use the below snippet to get the out parameters
$rs = $mysqli->query( ‘CALL get_user(1, @first, @last)’ );
$rs = $mysqli->query( ‘SELECT @first, @last’ );
while($row = $rs->fetch_object())
{
debug($row);
}
and the below snippet to retrieve the result set:
$rs = $mysqli->query( ‘CALL get_user(1, @first, @last)’ );
while($row = $rs->fetch_object())
{
debug($row);
}
Is there a way to call the stored procedure to retrieve both the results in a single PHP statement?