2016-09-15 24 views
1

數據庫錯誤找我有這樣的錯誤:CI旁邊4列

錯誤編號:1064

您的SQL語法錯誤;檢查 對應於您MariaDB的服務器版本使用 近「條件LIKE‘%鑿圓尺寸正確的語法手冊:在3號線

SELECT * FROM `inv_tool` WHERE (insert_date LIKE '%Chisel Round size: 120x3/440%' 
      || item_group LIKE '%Chisel Round size: 120x3/440%' || 
      item_name LIKE '%Chisel Round size: 120x3/440%' || 
      serial_number LIKE '%Chisel Round size: 120x3/440%' || 
      condition LIKE '%Chisel Round size: 120x3/440%') 

名120x3/440%’)」 : d:/ LocalWebServer /htdocs/ptes_is/application/models/Model_invsys.php

行號:73

如果我用這個超過3列:尋找

 public function find_in_tool ($find) { 
      $this -> db -> where ("(insert_date LIKE '%$find%' || 
          item_group LIKE '%$find%' || item_name LIKE '%$find%' || 
         serial_number LIKE '%$find%' || condition LIKE '%$find%')"); 
      $query = $this -> db -> get ('inv_tool') ; 
      return $query -> result() ; 
     } 

但如果我只用3,是沒有問題的。

 public function find_in_tool ($find) { 
      $this -> db -> where ("(insert_date LIKE '%$find%' || 
         item_group LIKE '%$find%' || item_name 
         LIKE '%$find%')"); 
      $query = $this -> db -> get ('inv_tool') ; 
      return $query -> result() ; 
     } 

但我真的需要超過3個......

回答

1

無關的列數,具有與MySQL/MariaDB的保留關鍵字(條件)做​​:https://dev.mysql.com/doc/refman/5.5/en/keywords.html

總結您的列名和表名反引號以避免衝突:

`condition` LIKE ... 
+0

如果我使用反引號,則沒有返回值。換句話說,我的列名在模型中不可讀,最後一個查詢表示'SELECT * FROM'inv_tool' WHERE('insert_date'LIKE'%cons%'||'item_group'LIKE'%cons%'||'item_name 'LIKE'%cons%'||'serial_number'LIKE'%cons%'||'condition'LIKE'%cons%')ORDER BY'insert_date' DESC' – Mauliardiwinoto

+1

那些不反引號,那些引號...... – Devon

+0

hohoho ...我的壞...和波浪號一樣嗎? – Mauliardiwinoto