简体   繁体   中英

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

$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..

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]')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM