I am stuck with a problem and have been searching for a solution since 6 hours.
I am calling a stored procedure using PHP to fetch tasks of different users by passing a bunch of user IDs.
I have the user IDs separated with ,
.
$user_id_string = "59,49"; // The user IDs have been converted as string using implode function on an array.
$d = DB::select(DB::raw('call fetch_tasks("'.$user_id_string.'")'));
And the stored procedure has only one simple query like:
select firstname from users where id in (uids)
Here I have declared uids as varchar(255) as IN parameter.
PROBLEM
When I call the function, I get firstname
of user id 59. If I hard code the values in SP, like (59,49) I am getting firstname of both the users.
EXPECTED
It should return firstname
for both.
Please, please help my guys.
UPDATE 1:
Hard coded:
CREATE DEFINER=`root`@`localhost` PROCEDURE `fetch_tasks`(IN `cur_lat` VARCHAR(255), IN `cur_lng` VARCHAR(255), IN `uids` VARCHAR(255)) NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER SELECT id, firstname from users where id in (59,49)
By passing variable:
CREATE DEFINER=`root`@`localhost` PROCEDURE `fetch_tasks`(IN `cur_lat` VARCHAR(255), IN `cur_lng` VARCHAR(255), IN `uids` VARCHAR(255)) NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER SELECT id, firstname from users where id in (uids)