如何用bindvalue和%准备语句? [英] How prepare statement with bindvalue and %?

查看:104
本文介绍了如何用bindvalue和%准备语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,当我尝试在看起来像这样的变量上使用bindvalues时,我遇到了一个问题:

Yes I have a issue when i try to use bindvalues on the variables that looked like this before:

users.firstname LIKE '$firstname%'

现在看起来像这样:

users.firstname LIKE ':firstname%'

但是它不起作用,也可以尝试这样做:

But it doesn't work, also tried this:

users.firstname LIKE :firstname%

出现语法错误.

正确的解决方案是什么?我还以为将%添加到bindValue(:firstname,$ firstname%)中,但我也需要在其他位置使用:firstname,也不应使用%..

What is the correct solution for this? I also thought adding the % in the bindValue(:firstname, $firstname%) but i need to use the :firstname in other places too that should not have the %..

帮助谢谢

推荐答案

好,将%添加到绑定值:

users.firstname LIKE :firstname

然后

$stmt->bindValue(':firstname', $firstname . '%');

但是,由于您要在其他地方使用:firstname,因此只需将此实例命名为其他名称即可:

But, since you're saying you need to use :firstname in other places, just name this instance something different:

users.firstname LIKE :firstnamewild

然后

$stmt->bindValue(':firstnamewild', $firstname . '%');

这篇关于如何用bindvalue和%准备语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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