2017-02-28 55 views
1

我使用活動記錄有問題,如果我有這樣的笨條件在當字段名稱包含空格

$data_array = array(
    'Code Employee' => 'AC01', 
    'Status Employee' => 'Y' 
); 

$this->db->where($data_array); 
$this->db->get('masteremp'); 
echo $this->db->last_query(); 

//Output query will be 
SELECT * FROM masteremp WHERE `Code` `Employee` = 'AC01' AND `Status` `Employee` = 'Y' 

我嘗試編輯DB_query_builder活動記錄,我添加此線2430

if(!empty($conditions)){ 
    for($index = 0; $index < sizeof($conditions); $index++){ 
    if (strpos($conditions[$index], '` `') !== false) { 
     $conditions[$index] = str_replace('` `', ' ', $conditions[$index]); 
    } 
    } 
} 

你有空間領域的方法嗎?我覺得我的方法是不是效率..感謝..

+0

最初使它像這樣: - '$ data_array中=陣列( 'CodeEmployee'=> 'AC01', 'StatusEmployee'=> 'Y' );' –

回答

4

IN codeigniter你可以這樣逃脫的價值觀和identifiers.Try一次..

更換

$this->db->where($data_array); 

隨着

$this->db->where($data_array,TRUE);//second parameter as TRUE 

Then

//Output query will be 
SELECT * FROM masteremp WHERE `Code Employee` = 'AC01' AND `Status Employee` = 'Y' 
+0

謝謝你,我不知道有參數來保護你的字段名稱 –

相關問題