为什么我们在某个地方使用fetch_array()而在其他地方使用result()?

I am following the Codeigniter framework. I just learn't how to connect to database and retrieve values. My model function is :-

public function getAll()
    {

        $query = $this->db->query("SELECT * FROM company_basic_details");

        return $query->result();

    }

Why do we not use fetch_array() or fetch_assoc() or mysqli* here. In the first OO php-mysql program I used :-

$query = "SELECT company_id FROM company_basic_details WHERE company_name = 'ABC'";
$result = $db->query($query);

while($row = $result->fetch_array())
{
    echo $row['company_id'];
}

Why we use fetch_array() at some place and result() in other places?

Look at closer. No difference?

$query->result()
$result->fetch_array()

$query->result() is array of associative array i.e. result set. $result->fetch_array() here you fetch one row from result set i.e. associative array.

In CodeIgniter, $query->result() will return an array of objects, whereas $query->result_array() will return a pure array.

See http://ellislab.com/codeigniter/user-guide/database/results.html

If you are using Codeigniter it's normal that it comes with his own set of functions. This function returns the query result as an array of objects, or an empty array on failure.

foreach ($query->result() as $row)
{
   echo $row->title;
   echo $row->name;
   echo $row->body;
}

It has the same behaviour of your fetch array. The difference is that it puts the results insinde the $row class.

You aren't, or shouldn't be.

result() or result_array() are the Codeigniter wrapper functions. You should always use those in CI applications.

These both are the entire result set returned. To access a single row (in a foreach, for example) you can use row() & row_array()

fetch_array() should not be used directly in CI