在PHP中的mysqli预编写语句中使用REGEXP [英] Using REGEXP inside mysqli prepared statement in PHP

查看:43
本文介绍了在PHP中的mysqli预编写语句中使用REGEXP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用(noob)代码进行如下简单的搜索过程:

I am trying to make a simple search process with (noob) codes like this:

$prep->prepare("SELECT * FROM details WHERE id REGEXP '?'");
$prep->bind_param("s", $search_query);

它给了我这个警告:

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

我猜可能是因为问号也用于RegExp(可选的前一个字符).

I am guessing it could be because the question mark is also used for RegExp (optional previous character).

关于如何在准备好的语句中使用REGEXP的想法(没有冲突的问号)?

Any idea about how to use REGEXP inside prepared statements (without conflicting question marks)?

谢谢.

推荐答案

取出?周围的单引号.您的代码应为:

Take out the single quotes around the ?. Your code should read:

$prep->prepare("SELECT * FROM details WHERE id REGEXP ?");
$prep->bind_param("s", $search_query);

就目前而言,您正在传递一个参数,但是单引号中的?被视为字符串,而不是参数标记.

As it stands now, you are passing in one param, but the ? in single quotes is treated as a string, not a parameter marker.

这篇关于在PHP中的mysqli预编写语句中使用REGEXP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆