Saturday, February 13, 2010

How to Find Records using MySQL Match Against Query in CakePHP

To use MySQL Match Against Query in CakePHP:

$needle = 'Search String';

$conditions = array( 
 "MATCH(Post.title) 
  AGAINST('$needle' IN BOOLEAN MODE)" 
  );
 $matches = $this->Post->find('all', array('conditions' => $conditions));

It does not need any explanation. I hope.

5 comments:

marti85cr said...

Hi,

shouldn't it be..?:

$conditions = array(
"MATCH(Post.title)
AGAINST('".$needle".' IN BOOLEAN MODE)"
);

I think the original post's query would search for '$needle' instead of the content of $needle.

correct my if I'm wrong.

marti85cr said...

Hi,

ignore my previous comment, I've checked it,

best regards.

You said...

Surely so! Thanks for pointing out to that.

Seo Rockers said...

amazing dear.. your all post is useful. Thanks for sharing..

PHP Developer

Siddhartha said...

Thanks..