mariadb version 10.4
$query->where('column', 'REGEXP', '[[:<:]]'.$string.'[[:>:]]');
This query provides a search with whole words only and that's working fine without special characters.
Example
Searching row:
foo (bar baz)
Filter:
$string = "(bar";
$query->where('column', 'REGEXP', '[[:<:]]'.$string.'[[:>:]]');
Error:
SQLSTATE[42000]: Syntax error or access violation: 1139 Got error 'missing )
Now I tried with addcslashes
and preg_quote
. I succeed to escape (
character with preg_quote
but the filter won't work for that string because the filter works with whole words.
Any suggestion for better filtering by the whole word will be also appreciated.
One more example
Searching row:
foo(bar baz
Filter:
$filter = 'foo(bar';
$query->where('column', 'REGEXP', '[[:<:]]'.$string.'[[:>:]]');
If (
will be escaped the search will not work