在准备好的mysqli语句中多次使用一个参数 [英] Using one parameter multiple times in prepared mysqli-statement

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

问题描述

是否可以在准备好的 mysqli 语句中多次使用一个参数,而仅将其绑定一次?
像这样的东西

Is it possible to use one parameter in a prepared mysqli-statement multiple times with only binding it one time?
something like this

$stmt = $mysqli->prepare(SELECT * FROM user WHERE age BETWEEN ?1 - 2 AND ?1 + 2);
$stmt->bind_param('i', $myAge);

我认为使用PDO可以做到这一点,但是我不知道如何使用mysqli做到这一点.

I think this is possible with PDO, but I don't konw how to do this with mysqli.

推荐答案

只需结束这个问题:

答案是.

如果您只想绑定一次参数,并且在查询中多次使用它,则必须使用PDO,这可能还需要特殊的配置.

If you want to bind a parameter only one time and using it multiple times in a query you have to use PDO and this maybe also needs a special configuration.

但是,根据很好的答案或.

But there seems to be more reasons to use PDO instead of mysqli, according to this great answer or this.

但是请确保有解决方法.查看该问题的其他答案.

But sure there are workarounds. See the other answers to this question.

这篇关于在准备好的mysqli语句中多次使用一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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