Stored procedure (works fine): Internal server error
<p>I'm using this stored procedure: <a href="http://pastebin.com/Jn8F6SD7" rel="nofollow">http://pastebin.com/Jn8F6SD7</a></p>

<p>This runs fine in the following cases:</p>

<ol>
<li>mysql console</li>
<li>PHPMyAdmin "execute" button: <a href="https://gyazo.com/7b27d5ce5bae6f8dfa143b159daa9248" rel="nofollow">https://gyazo.com/7b27d5ce5bae6f8dfa143b159daa9248</a></li>
</ol>

<p>The same Stored Procedure gives errors in the following cases:</p>

<ol>
<li>PHPMyAdmin SQL-tab: <a href="https://gyazo.com/91e2e88e27d0e24911bcae47f608681a" rel="nofollow">https://gyazo.com/91e2e88e27d0e24911bcae47f608681a</a> (Internal server error)</li>
<li>PHP mysqli functions (The DirectAdmin logs show: out of memory, the php error is: packets out of order)</li>
</ol>

<p>I'm using PHP 7.0 and MySQL 5.6</p>