Good day everyone !
i have a mysql stored procedure that should loop through an arbitrary array of strings (so to speak). here's it:
CREATE PROCEDURE StupidProcedure (INOUT Stringarray VARCHAR(100), IN msg VARCHAR (100) )
BEGIN
DECLARE indx INT;
DECLARE len INT;
DECLARE valu INT;
SET @indx = 0;
SET @len = 0;
WHILE LOCATE(',', @Stringarray , @indx + 1) > 0 DO
SET @len = LOCATE(',', @Stringarray , @indx + 1) - @indx;
SET @valu = SUBSTRING(@Stringarray , @indx, @len);
SELECT CONCAT(@msg, @valu) INTO msg;
SET @indx = LOCATE(',', @Stringarray , @indx + @len) + 1;
END WHILE;
END
Now, i needed to be sure that concatenated @msg has received all data in @Stringarray after the loop. Using php, i simply did this:
$StupidArray = "Boys, are, not, smiling, at, all,";
if (!$db->query(" SET @msg = ''; SET @Stringarray = '\' $StupidArray '\'; " ) || !$db->query(" CALL StupidProcedure (@Stringarray, @msg)") ){
echo "CALL to StupidProcedure failed:".print_r($db->errorInfo());
}else{
$res = $db->query("SELECT @msg as _p_out");
$row = $res->fetch();
print_r($row['_p_out']);
}
What i got in return was 'all', the last is $StupidArray. what am i doing wroing ? OR is it my loop thats failing ?
thanks.