1

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.

0

1 Answer 1

1
$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.

Sign up to request clarification or add additional context in comments.

3 Comments

Please add an explanation to your answer
you just forget to add the result() method in the end, and you print the code igniter query builder obj
oh, it didn't add something like that on the active records, simply showed the get_where function. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.