title: Passing array through bind_param
body: <p>I'm passing an array of values through a <code>bind_param</code> function, the way I do this is like this:</p>
  <pre><code>&lt;?php
  class Query{
      private $_mysqli;
  
      /*
       * @param object $mysqli
       */
      public function __construct($mysqli)
      {
          $this-&gt;_mysqli = $mysqli;
      }
  
      /*
       * @param string query
       * @param string $types
       * @param array $values
       */
      public function read($query = &quot;&quot;, $type = &quot;&quot;, $params = array())
      {
          $query = ($query === &quot;&quot;) ? die(&quot;Read error: Query&quot;) : $query;
          $type = ($type === &quot;&quot;) ? die(&quot;Read error: Type&quot;) : array($type);
          $params = (count($params) == 0) ? die(&quot;Read error: Params&quot;) : $params;
  
          $values = array();
          foreach($params as $key =&gt; $value) {
              $values[$key] = &amp;$params[$key];
          }
  
          if ($stmt = $this-&gt;_mysqli-&gt;prepare($query))
          {
              call_user_func_array(array($stmt, &quot;bind_param&quot;), array_merge($type, $values));
              $stmt-&gt;execute();
              $fields = array();
              for($i=0; $i&lt;count($params); $i++){
                  $fields[$i] = $params[$i];
              }
              call_user_func_array(array($stmt, &quot;bind_result&quot;), $fields);
  
              $array = array();
              while($data = $stmt-&gt;fetch())
              {
                  $array[] = $data;
              }
  
              return $array;
          }
      }
  }
  </code></pre>
  <p>This is the way I use my function</p>
  <pre><code>&lt;?php
  //$mysqli is the mysqli connection
  $query = new Query($mysqli);
  
  $query_str = &quot;SELECT * FROM users WHERE voornaam = ? AND achternaam = ?&quot;;
  $types = &quot;ss&quot;;
  $params = array(&quot;Firstname&quot;, &quot;Lastname&quot;);
  var_dump($query-&gt;read($query_str, $types, $params));
  ?&gt;
  </code></pre>
  <p>The part where I get stucked is:</p>
  <pre><code>&lt;?php
  $fields = array();
  for($i=0; $i&lt;count($params); $i++){
      $fields[$i] = $params[$i];
  }
  call_user_func_array(array($stmt, &quot;bind_result&quot;), $fields);
  
  $array = array();
  while($data = $stmt-&gt;fetch())
  {
      $array[] = $data;
  }
  ?&gt;
  </code></pre>
  <p>Im not sure where it goes wrong, I have a feeling at the while loop.
  hope you guys can help me making this function working :)</p>