I'm trying to implement a database search, by using match
, against
and fulltext indexing
. So, when I did the search, it did not work as expect, no errors and no results was given. I'm querying by using Codeigniter.
Here is my PHP query code:
$clean_keyword = trim($keywords); //$keyword is passed to the function`
$this->db->select('question, answer')
->from('QA')
->where('MATCH(question) AGAINST("'.$clean_keyword.'")', null, FALSE);
$query = $this->db->get(); //execute the previous statement and save the result in a variable.
No errors from codeigniter/MySQL was given.
I tried to debug the $query
variable by doing var_dump($query)
, see the results (N.B. The important part is result_array
with size=0
):
object(CI_DB_mysql_result)[19]
public 'conn_id' => resource(30, mysql link persistent)
public 'result_id' => resource(38, mysql result)
public 'result_array' =>
array (size=0)
empty
public 'result_object' =>
array (size=0)
empty
public 'custom_result_object' =>
array (size=0)
empty
public 'current_row' => int 0
public 'num_rows' => int 0
public 'row_data' => null
MySQL table schema:
CREATE TABLE `QA` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`question` varchar(200) CHARACTER SET utf8 NOT NULL,
`answer` varchar(500) CHARACTER SET utf8 NOT NULL,
`u_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `question` (`question`)
) ENGINE=MyISAM