update page now

Voting

: four minus zero?
(Example: nine)

The Note You're Voting On

bb at servertje dot nl
17 years ago
Although inspired by an earlier post, this method could be added to any of your database objects. It's an object oriented implementation of an earlier post.

The method returns an array with objects representing a row. Each property represents a column and its value.
 
<?php
    private function getresult($stmt)
    {
      $result = array();
      
      $metadata = $stmt->result_metadata();
      $fields = $metadata->fetch_fields();

      for (;;)
      {
        $pointers = array();
        $row = new stdClass();
        
        $pointers[] = $stmt;
        foreach ($fields as $field)
        {
          $fieldname = $field->name;
          $pointers[] = &$row->$fieldname;
        }
        
        call_user_func_array(mysqli_stmt_bind_result, $pointers);
        
        if (!$stmt->fetch())
          break;
        
        $result[] = $row;
      }
      
      $metadata->free();
      
      return $result;
    }
?>

<< Back to user notes page

To Top