Answer the question
In order to leave comments, you need to log in
Why is mysql query returning zero rows?
There is a table:
CREATE TABLE `chat` (
`id` int(10) unsigned NOT NULL auto_increment,
`message` varchar(200) default NULL,
`answer` varchar(200) default NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `title` (`message`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
INSERT INTO `chat` VALUES (1, 'hi', 'privet');
$get = mysql_fetch_row(mysql_query("SELECT answer FROM chat WHERE MATCH(message) AGAINST('hi')"));
$answer = $get["answer"];
Answer the question
In order to leave comments, you need to log in
Perhaps the error is in the sql query itself. On the test data, the result of the query is indeed empty because hi does not match a row from the database.
There are two reasons for this:
1) The word `hi` occurs in more than half of the records in the table (this is true for a one-row table). Then hi is included in the list of stop words, and no search is performed on them. This behavior can be bypassed by enabling boolean mode
2) The word `hi` is too short, and the tokenizer throws it out of consideration when creating an index for the string. For longer words the query works fine: sqlfiddle.com/#!2/5bd24/8
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question