stored procedure cannot loop an array of string <pre><code>$StupidArray = "Boys, are, not, smiling, at, all,"; if (!$db-&gt;query(" SET @msg = ''; SET @Stringarray = '\' $StupidArray '\'; " ) || !$db-&gt;query(" CALL StupidProcedure (@Stringarray, @msg)") ) { echo "CALL to StupidProcedure failed:".print_r($db-&gt;errorInfo()); } else { $res = $db-&gt;query("SELECT @msg as _p_out"); $row = $res-&gt;fetch(); print_r($row['_p_out']); } </code></pre> <p>I have this mysql stored procedure that should loop through an arbitrary array of strings.</p> <pre><code>CREATE PROCEDURE StupidProcedure (INOUT Stringarray VARCHAR(100), IN msg VARCHAR (100) ) BEGIN /*Table loop variable*/ DECLARE indx INT; DECLARE len INT; DECLARE valu INT; SET @indx = 0; SET @len = 0; WHILE LOCATE(',', @Stringarray , @indx + 1) &gt; 0 DO SET @len = LOCATE(',', @Stringarray , @indx + 1) - @indx; SET @valu = SUBSTRING(@Stringarray , @indx, @len); SELECT CONCAT(@msg, @valu) INTO msg; /* For Debugging purpose*/ SET @indx = LOCATE(',', @Stringarray , @indx + @len) + 1; /*increment loop*/ END WHILE; END </code></pre> <p>Now, I needed to be sure that concatenated <code>@msg</code> has received all data in <code>@Stringarray</code> after the loop. Using php, I simply did this:</p> <pre><code>$StupidArray = "Boys, are, not, smiling, at, all,"; if (!$db-&gt;query(" SET @msg = ''; SET @Stringarray = '\' $StupidArray '\'; " )) { echo "CALL to StupidProcedure failed:".print_r($db-&gt;errorInfo()); } else { $res = $db-&gt;query("SELECT @msg as _p_out"); $row = $res-&gt;fetch(); print_r($row['_p_out']); }​ </code></pre> <p>What I got in return was <code>all</code>, the last is <code>$StupidArray</code>. What am I doing wrong? OR is it my loop that is failing?</p>