title: Return mysqli query result as an array in PHP
body: <p>I've been searching the internet for a while now, but since I'm new to MySQLi, I cannot solve this problem myself. This is my code so far. I want to return the result as an array.</p>
  
  <pre><code>function myFunction($u_id, $mysqli){
     $userinfo = "SELECT email, name, street, placename FROM users WHERE u_id = ? LIMIT 1";
     if($stmt = $mysqli-&gt;prepare($userinfo)) {
        $stmt-&gt;bind_param('i', $u_id);
        $stmt-&gt;execute();
        if(!$stmt-&gt;execute()) { 
              echo $stmt-&gt;error.' in query: '.$userinfo; 
        } else {
          //this is what i found somewhere on the internet, and it gives me an array with the right keys but empty values.
          $meta = $stmt-&gt;result_metadata();
          while ($field = $meta-&gt;fetch_field()) { 
              $var = $field-&gt;name; 
              $$var = null; 
              $parameters[$var] = &amp;$$var; 
          } 
          return $parameters;
      }
      $stmt-&gt;close();
  }}
  </code></pre>
  
  <p>Hopefully someone can help me get this code working, or help me find an alternative.</p>