2017-01-26 81 views
1

有這個疑問,笨3 get_where SQL查詢功能

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

我遇到的問題是,每當我嘗試呼應它(通過print_r的),這是結果,爲什麼它返回一個對象?

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] => 
) 

是不是應該返回一個數組值?

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

它並不顯示有所以我只是假設在活動記錄類中的任何查詢將返回值。

回答

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

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

請添加解釋你的答案 –

+0

你只是忘記添加的結果()方法到底, 和打印的代碼點火器查詢生成器的obj – Nevo

+0

哦,沒有在活動記錄中添加類似內容,只是顯示了get_where函數。謝謝! – john