W
W
WebforSelf2021-08-07 14:36:30
PHP
WebforSelf, 2021-08-07 14:36:30

Problem with regexp on mysql 8.0.26?

There is a regexp function in the php code which is on 5.7. mysql works as it should.

$show_filter_array[$k] = $this->db->placehold($k." regexp '(?)'", intval($show_filter_array[$k]));

Transferred the site to another server
After that, the function stopped working on mysql 8.0.26
In version 8, the logic of working with regexp has changed
I tried to do this
$show_filter_array[$k] = $this->db->placehold($k." regexp '\\b(?)\\b'", intval($show_filter_array[$k]));

But still doesn't work. Falling back to old musk is not an option, because. There is already another site up and running.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-08-09
@Akina

According to MySQL 5.7 Reference Manual / ... / Regular Exp...

,
These markers stand for word boundaries.

According to MySQL 8.0 Reference Manual / ... / Regular Exp...
The Spencer library supports word-beginning and word-end boundary markers ( and notation). ICU does not. For ICU, you can use \b to match word boundaries; double the backslash because MySQL interprets it as the escape character within strings.

So the approach is correct.
But you do not take into account that the slash must be quoted for both PHP and MySQL. Those. there should be not two, but four.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question