U
U
uranus2352014-10-19 13:41:10
PHP
uranus235, 2014-10-19 13:41:10

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');

Upon request
$get = mysql_fetch_row(mysql_query("SELECT answer FROM chat WHERE MATCH(message) AGAINST('hi')"));
$answer = $get["answer"];

no result is returned. Help me find the problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lolshto, 2014-10-19
@uranus235

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

S
Sergey, 2014-10-19
Protko @Fesor

php.net/manual/ru/function.mysql-query.php - read right after the header. DEPRECATED !
And yes, 0 is not 0 but false. You need to look at what the error was (mysql_error function).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question