将PHP准备的语句与LIKE结合使用 [英] Combine PHP prepared statments with LIKE

查看:98
本文介绍了将PHP准备的语句与LIKE结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何将PHP准备好的语句与LIKE结合起来吗?即

Anyone know how to combine PHP prepared statements with LIKE? i.e.

"SELECT * FROM table WHERE name LIKE %?%";

推荐答案

%符号需要放在您分配给该参数的变量中,而不是查询中.

The % signs need to go in the variable that you assign to the parameter, instead of in the query.

我不知道您使用的是mysqli还是PDO,但是使用PDO就像:

I don't know if you're using mysqli or PDO, but with PDO it would be something like:

$st = $db->prepare("SELECT * FROM table WHERE name LIKE ?");
$st->execute(array('%'.$test_string.'%'));

:为mysqli用户提供以下内容.

EDIT :: For mysqli user the following.

$test_string = '%' . $test_string . '%';
$st->bind_param('s', $test_string);
$st->execute();

这篇关于将PHP准备的语句与LIKE结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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