全文mysql搜索并匹配完全字符串

Ok this is doing my grey matter in I've read and been through mysql and looked at various options and I can only think its so obvious I'm just blind.

In short i'm making a tag cloud and part of the process is to verify if the word exists and if so +1 but it has to be the exact phrase.

So I took the view that fulltext search would be the best option.

So as an example.

$string = "hair dryer";

$string = '"'.$string.'"'; //enclose string in quotation marks to define must be an exact match



 //$string = mysqli_real_escape_string($mysqli,$string); // removed to see if this was effecting the result.

 $sql = "SELECT * FROM `search_keyword` WHERE Match (`keyword`) Against ('$string' IN BOOLEAN MODE) LIMIT 1";
 $result=mysqli_query($mysqli,$sql);

So the test was in the DB I have a line with the word "hair dryer" and it matches it - good result

However if I change the string to "hair" it still pulls out "hair dryer" which it shouldn't do as its not an exact match.

I've read all over and every way I try this I get the wrong result.

(
[0] => Array
    (
        [keyword] => hair dryer
        [id] => 25
    )

 )  /// should be empty and hair as a single row is not found

Please any advice is welcomed :-)

You could do it with php. First transform your string into an array and then compare both arrays to see if there is a match.

      $string = explode(" ",$string); 
      $sql = "SELECT keyword FROM search_keyword";
     $result=mysqli_query($mysqli,$sql);
$compareArrays = array_intersect($result,$string);
       if (is_array($compareArrays) && count($compareArrays) > 0) {

Do something with the result as if $compareArrays is greter than one, it means you have an exact match. array_intersect compares 2 arrrays to see if there is an exact match. This way I don't think you would get a match with 'hair' as a string but you would get one with 'hair dryer'. Does this work?