title: How to get array of row objects from my result in mysqli prepared query
body: <p>I would like to return all the results from my prepared query (mysqli) as objects in an array but i cant find a fetchall method or something similar. How do i go about this?</p>
  
  <pre><code>public function getImageResults ($search_term)
  {
          if (empty($search_term))
              return false;
  
          $image_query = $this-&gt;db_connection-&gt;stmt_init();
  
          $image_query_sql =
          "
              SELECT 
                  Images.url as url
              FROM 
                  Images, ImageSearch, ImageSearchResults 
              WHERE 
                  ImageSearch.search_string = ? AND
                  ImageSearchResults.search_id = ImageSearch.id AND
                  ImageSearchResults.image_id = Images.id AND
  
                  Images.deleted = 0 AND
                  ImageSearch.deleted = 0 AND
                  ImageSearchResults.deleted = 0
          ";
  
          if ($image_query-&gt;prepare($image_query_sql))
          {
              $image_query-&gt;bind_param('s', $search_term);
  
              $image_query-&gt;execute();
              $image_query-&gt;store_result();
              $image_query-&gt;bind_result($url);
  
              return //need to return the entire result set here... any ideas?
          }
  
          return false;
  }
  </code></pre>
  
  <p>I found this code on the net which kinda works but i get this error when i use it </p>
  
  <blockquote>
    <p>Notice: Use of undefined constant
    mysqli_stmt_bind_result - assumed
    'mysqli_stmt_bind_result'</p>
  </blockquote>
  
  <pre><code>private function getresult ($stmt)
      {
          $result = array();
  
          $metadata = $stmt-&gt;result_metadata();
          $fields = $metadata-&gt;fetch_fields();
  
          for (;;)
          {
              $pointers = array();
              $row = new stdClass();
  
              $pointers[] = $stmt;
              foreach ($fields as $field)
              {
                  $fieldname = $field-&gt;name;
                  $pointers[] = &amp;$row-&gt;$fieldname;
              }
  
              call_user_func_array(mysqli_stmt_bind_result, $pointers);
  
              if (!$stmt-&gt;fetch())
                  break;
  
              $result[] = $row;
          }
  
          $metadata-&gt;free();
  
          return $result;
      }
  </code></pre>