我正在尝试使用正则表达式查询 MYSQL 数据库。我正在寻找具有此模式 1234X32X12 的列下的值。
我写了一些伪代码,但我不熟悉正则表达式,所以我希望有人能帮助我。
代码:
if ($transposed_array[$i][0] starts with number)
{
$sid = regex something /^[0-9]*/
$gid = regex something /X[0-9]*X/
$gid = remove first and last character from $gid
$qid = regex something /[0-9]*$/
$question_text = mysql_query("select question from table where sid = ".$sid." and gid = ".$gid." and qid = ".$qid." limit 1");
$transposed_array[$i][0] = $question_test
}
如有任何帮助,我们将不胜感激!
最佳答案
MySQL 在其 SQL 命令中直接支持正则表达式匹配,查看 its manual :
select col from table where col regexp '^h';
关于php - 在PHP中使用正则表达式查询MYSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13075058/