We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to use regexp in Model::find()

How to use regexp in Model::find()

when use command like this SELECT FROM user WHERE username regexp 'contest3_.'

I try User::find("username regexp 'contest3_.*'");

it have error.

Syntax error, unexpected token IDENTIFIER(regexp), near to ' 'contest3.'', when parsing: SELECT [PSUOJ\Models\User]. FROM [PSUOJ\Models\User] WHERE username regexp 'contest3.*' (89)

edited Oct '14

I'm not sure if Phalcon supports regexp, but in this example, couldn't you just use:

User::find("username like 'contest3_%'");


Gareth is right (and I also use it), but you are also wrong with your clause. I reproduced your SQL with a DB I have, and also gives me error when using *. You only have to write contest_3. Try it.