[RESOLVED] [MySQL 5.1 & PHP] Prepared STMT with REGEX
This is SQL query stored in PHP's var:
PHP Code:
$sql =
'SELECT t1.for
FROM t1, t2
WHERE t1.for = t2.for && t1.for
REGEXP \'[^0-9]?[^0-9]\'';
Question mark in a middle of regexp statement, is supposed to be a binding placeholder, for prepared statement!
So when I escape it like:
PHP Code:
$sql =
'SELECT t1.for
FROM t1, t2
WHERE t1.for = t2.for && t1.for
REGEXP \'[^0-9]\\\?[^0-9]\'';
It just escaped special meaning in regexp itself and is now litteral symbol which is part of a pattern.
I want it to become(?) a binding placeholder inside of regexp pattern.
Re: [MySQL 5.1 & PHP] Prepared STMT with REGEX
It doesn't matter anymore, as I've found a solution.
It is as follows:
PHP Code:
$sql =
'SELECT t1.for
FROM t1, t2
WHERE t1.for = t2.for && t1.for
REGEXP CONCAT(\'[^0-9]+\', ?, \'[^0-9]+\')';
And Voila! :p
Now ? placeholder works for this prepared select statement. :thumb: