Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate dynamic number Of variables
    text
    copied!<p><strong>EDIT:</strong> after discussing <a href="https://stackoverflow.com/questions/8630152/php-eval-is-this-exploitable-in-my-code-dynamic-arguments">here click here</a> i decided to use Francis Avila solution, it is securer, but I didn't find a way to exploit my way, only everybody says its security risk to use eval(). If you find a way, to exploit my way, please post a comment. :-), so that i understand it and also another users, who use eval :-)</p> <p>One more thing not to use eval(), it is slower, for what i wanted todo.</p> <p><strong>EDIT:</strong></p> <p>One positive thing, also is in Francis Avila solution is, you need only specific only 2 vars, $SQL + $INPUT, no need more brother with $output.</p> <p><strong>EDIT: removed the old question and replaced it with this, so you have maybe a better idea what i want to do.</strong></p> <p>i found a solution how to make a dynamic number of Variables, but its not the optimal solution. Cause i need to edit / add more lines, if the number of variables gets higher than 8. So is there a way, to make that dynamic on dont relay on the <strong>switch function</strong></p> <pre><code>public function readDB($readdb, $input, $output1) { $sql = $readdb; $stmt = $this-&gt;mysqli-&gt;prepare($sql); if(!empty($input) &amp;&amp; is_array($input)) { $inputn = count($input); switch($inputn) { case "1": $stmt-&gt;bind_param('s', $input[0][0]); break; case "2": $stmt-&gt;bind_param('ss', $input[0][0], $input[1][0]); break; case "3": $stmt-&gt;bind_param('sss', $input[0][0], $input[1][0], $input[3][0]); break; case "4": $stmt-&gt;bind_param('ssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0]); break; case "5": $stmt-&gt;bind_param('sssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0]); break; case "6": $stmt-&gt;bind_param('ssssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0], $input[6][0]); break; case "7": $stmt-&gt;bind_param('sssssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0], $input[6][0], $input[7][0]); break; case "8": $stmt-&gt;bind_param('ssssssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0], $input[6][0], $input[7][0], $input[8][0]); break; default: break; } } if (!$stmt) {throw new Exception($mysqli-&gt;error);} $stmt-&gt;execute(); $stmt-&gt;store_result(); $checker = $stmt-&gt;num_rows; if($checker !== 0) { if(!empty($output1)) { switch($output1) { case "1": $stmt-&gt;bind_result($output[0]); while ($stmt-&gt;fetch()) { $results[] = array($output[0]); } break; case "2": $stmt-&gt;bind_result($output[0], $output[1]); while ($stmt-&gt;fetch()) { $results[] = array($output[0], $output[1]); } break; case "3": $stmt-&gt;bind_result($output[0], $output[1], $output[2]); while ($stmt-&gt;fetch()) { $results[] = array($output[0], $output[1], $output[2]); } break; case "4": $stmt-&gt;bind_result($output[0], $output[1], $output[2], $output[3]); while ($stmt-&gt;fetch()) { $results[] = array($output[0], $output[1], $output[2], $output[3]); } break; case "5": $stmt-&gt;bind_result($output[0], $output[1], $output[2], $output[3], $output[4]); while ($stmt-&gt;fetch()) { $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4]); } break; case "6": $stmt-&gt;bind_result($output[0], $output[1], $output[2], $output[3], $output[4], $output[5]); while ($stmt-&gt;fetch()) { $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4], $output[5]); } break; case "7": $stmt-&gt;bind_result($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6]); while ($stmt-&gt;fetch()) { $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6]); } break; case "8": $stmt-&gt;bind_result($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6], $output[7]); while ($stmt-&gt;fetch()) { $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6], $output[7]); } break; default: echo "HERE"; break; } } } else { $results = "NO RESULTS"; } $stmt-&gt;fetch(); $stmt-&gt;close(); $this-&gt;checker = $checker; $this-&gt;results = $results; $this-&gt;result = array('num_rows' =&gt; $checker, $results); return $this-&gt;results; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload