3
$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();

引发此错误:

语法错误或访问冲突:1139 从正则表达式中得到错误“无效字符范围”

是否有可能做到这一点..

4

1 回答 1

5

占位符只能用于可以出现值的地方,不能嵌入字符串中。尝试:

$query = "SELECT * FROM `mytable` WHERE `file` REGEXP CONCAT('[', :val, '-9]')";
于 2012-09-23T01:21:24.467 回答