将CodeIgniter查询转换为正常的mySQL查询

时间:2017-01-14 17:36:51

标签: php mysql codeigniter

如何将CodeIgniter中编写的此函数转换为普通的MySQL查询?

public function getUserAttend ( $User_ID , $Date_From , $Date_To )
{
    $this -> db -> select 
            ( ''
            . '(select attend_permission_confirmed from ts_permission pr  where pr.attend_in_attend_id = att.attend_id LIMIT 1 ) as attend_permission_confirmed_out '
            . ',(select attend_permission_confirmed from ts_permission pr  where pr.attend_out_attend_id = att.attend_id   LIMIT 1 ) as attend_permission_confirmed_in '
            . ',`attend_id`, `attend_date`, `attend_user`, `attend_time_in`, `attend_time_out`, `attend_ctime_in`, `attend_ctime_out`, `attend_notes_in`, `attend_notes_out`, `attend_modifiedby`, `attend_checkoutip`'
            . ', `attend_official_in`, `attend_official_out`, `attend_morning_permission` '
            , FALSE );

    $this -> db -> order_by ( 'attend_id' , 'ASC' );
    $res = $this -> db -> get_where ( "ts_attendance as att" , array (
        "attend_user" => $User_ID ,
        "attend_date >= " => $Date_From ,
        "attend_date < " => $Date_To
            )
    );

    return $res -> result_array ();
}

请注意,我没有Php CodeIgniter框架的专业知识。 你能解释一下这段代码在mySQL中的含义吗?

1 个答案:

答案 0 :(得分:2)

您可以使用Codeigniters内​​置函数last_query()

$qstring= $this->db->last_query();

更多信息here