如果SQL没有返回任何内容,我想搜索单词+数字,我会将其默认为完整的LIKE
搜索,有没有办法在SQL中实现这样的正则表达式?
示例:
$queryWord = potato
像这样:
$sql = "SELECT * FROM `words` WHERE `searchWord` LIKE '$queryWord+number';";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) == 0) {
$sql = "SELECT * FROM `words` WHERE `searchWord` LIKE '%$queryWord%';"; // full search
$result = mysqli_query($con, $sql);
// etc etc
}
答案 0 :(得分:3)
只需将您的查询更改为:
$sql = "SELECT * FROM `words` WHERE `searchWord` REGEXP '$queryWord(\d{1,4})';";