0

I have the following conditions for a model that finds a list of subjects:

$subjects = $this->PtlSubject->find('all', array(

    'conditions' => array('PtlSubject.title RLIKE' => '[[:<:]]'.$value),
    'limit' => 6

));

When running the query I get a mysql error:

1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '[[:<:]]mat' LIMIT 6' at line 1

Is there another way you can use REGEX word boundaries for mysql queries in CakePHP?

Thanks in advance for any help, much appreciated :)

jahilldev
  • 3,520
  • 4
  • 35
  • 52

1 Answers1

2

I'm not sure if Cake knows how to deal with RLIKE. You can always pass the whole condition directly, like this:

 'conditions' => "PtlSubject.title RLIKE '[[:<:]]$value'"

Just make sure $value is properly escaped, to avoid injection.

Community
  • 1
  • 1
bfavaretto
  • 71,580
  • 16
  • 111
  • 150