Mauliardiwinoto
Mauliardiwinoto

Reputation: 107

CI database error find on next 4th column

I have this error :

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'condition LIKE '%Chisel Round size: 120x3/440%')' at line 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%')

Filename: D:/LocalWebServer/htdocs/ptes_is/application/models/Model_invsys.php

Line Number: 73

If I use this more than 3 column to find :

       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 () ;
        }

But if I use only 3, there is no problem.

       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 () ;
        }

But i really need more than 3 ...

Upvotes: 1

Views: 23

Answers (1)

Devon Bessemer
Devon Bessemer

Reputation: 35347

Has nothing to do with the number of columns, has to do with MySQL/MariaDB reserved keywords (condition): https://dev.mysql.com/doc/refman/5.5/en/keywords.html

Wrap your column names and table names in backticks to avoid conflicts:

`condition` LIKE ...

Upvotes: 1

Related Questions