Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Prepared Statements... Bind variable as numeric range in REGEXP?

Tags:

regex

php

mysql

pdo

$query = "SELECT * FROM `mytable` WHERE `file` REGEXP '[:val-9]'";
$stmt = $dbh->prepare($query);
$stmt->bindValue(':val', '1'); //I have also tried 1 without quotes
$stmt->execute();

Throws this error:

Syntax error or access violation: 1139 Got error 'invalid character range' from regexp

Is it possible to do this..

like image 321
Norse Avatar asked Oct 25 '25 09:10

Norse


1 Answers

Placeholders can only be used where a value can appear, not embedded in strings. Try:

$query = "SELECT * FROM `mytable` WHERE `file` REGEXP CONCAT('[', :val, '-9]')";
like image 140
Barmar Avatar answered Oct 27 '25 23:10

Barmar