phparrayscodeigniterresultset

codeigniter 3 get_where sql query function


I have this query,

$acc = $this->db->get_where('accounts', array('username' => $username), 1);

The problem I'm having is that, whenever I try to echo it (via print_r) this is the result, why is it returning an object?

CI_DB_mysqli_result Object ( 
    [conn_id] => mysqli Object ( 
        [affected_rows] => 1 
        [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $ 
        [client_version] => 50011 
        [connect_errno] => 0 
        [connect_error] => 
        [errno] => 0 
        [error] => 
        [error_list] => Array ( ) 
        [field_count] => 5 
        [host_info] => localhost via TCP/IP 
        [info] => 
        [insert_id] => 0 
        [server_info] => 5.7.14 
        [server_version] => 50714 
        [stat] => Uptime: 16045 Threads: 3 Questions: 382 Slow queries: 0 Opens: 121 Flush tables: 1 Open tables: 114 Queries per second avg: 0.023 
        [sqlstate] => 00000 
        [protocol_version] => 10 
        [thread_id] => 3 
        [warning_count] => 0 
    ) 
    [result_id] => mysqli_result Object ( 
        [current_field] => 0 
        [field_count] => 5
        [lengths] => 
        [num_rows] => 1 
        [type] => 0 
    ) 
    [result_array] => Array ( ) 
    [result_object] => Array ( ) 
    [custom_result_object] => Array ( ) 
    [current_row] => 0 
    [num_rows] => 
    [row_data] => 
)

Isn't it supposed to return an array of values?

https://www.codeigniter.com/userguide2/database/active_record.html#select

It doesn't show there so i'm just assuming that any query in the active records class would return values.


Solution

  • $acc = $this->db->get_where('accounts', array('username' => $username), 1)->result();
    

    or

    $acc = $this->db->get_where('accounts', array('username' => $username), 1)->result_array();
    

    You printed query builder object, insted of mysql result object.