How prepare statement with bindvalue and %?

China☆狼群 提交于 2019-12-02 03:27:36

问题


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

users.firstname LIKE '$firstname%'

Now it looks like this:

users.firstname LIKE ':firstname%'

But it doesn't work, also tried this:

users.firstname LIKE :firstname%

And got some syntax error..

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 %..

Help thank you


回答1:


Ok, add the % to the bound value:

users.firstname LIKE :firstname

And then

$stmt->bindValue(':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

And then

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


来源:https://stackoverflow.com/questions/4783750/how-prepare-statement-with-bindvalue-and

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!