I am trying to implement a search function in my codeIgniter project. I have a table called product_search, where I set the full-text index using the following command:
ALTER TABLE `product_search` ADD FULLTEXT (`prod_title`, `prod_desc`)
Then I look through it using the following codeIgniter code:
$this->db->select("prod_id");
$this->db->where("MATCH (`prod_title`, `prod_desc`) AGAINST ('{$searchStr}')");
$this->db->or_where("prod_id LIKE '%{$searchStr}%'");
$this->db->or_where("prod_sku LIKE '%{$searchStr}%'");
$this->db->or_where("prod_title LIKE '%{$searchStr}%'");
$this->db->or_where("prod_desc LIKE '%{$searchStr}%'");
$query = $this->db->get("product_search");
This, however, leads to the following error:
Error Number: 1064
You have an error in the SQL syntax; check the manual that matches the version of your MySQL server for the correct syntax to use next to 'AGAINST (silk) OR prod_idLIKE'% silk% 'OR prod_skuLIKE'% silk% 'OR `prod' on line 3
SELECT prod_id FROM (product_search) WHERE MATCH (prod_title, prod_desc) ('') prod_id LIKE '% silk%' OR prod_sku LIKE '% silk % 'OR prod_title LIKE'% silk% 'OR prod_desc LIKE'% silk% '
: models/products_model.php
: 430
MATCH?
MATCH , :
: 1191
FULLTEXT,
SELECT prod_id FROM (product_search) (prod_title, prod_desc) ('') prod_id LIKE '% silk%' prod_sku LIKE '% silk%' OR prod_title LIKE '% silk%' OR prod_desc LIKE '% silk%'
: models/products_model.php
: 430
.
?