$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();
抛出这个错误:
Syntax error or access violation: 1139 Got error 'invalid character range' from regexp
这有可能吗..
最佳答案
占位符只能用在值可以出现的地方,不能嵌入字符串中。尝试:
$query = "SELECT * FROM `mytable` WHERE `file` REGEXP CONCAT('[', :val, '-9]')";
关于PHP 准备语句...将变量绑定(bind)为 REGEXP 中的数字范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12548926/