在准备好的mysqli语句中多次使用一个参数 [英] Using one parameter multiple times in prepared mysqli-statement
问题描述
是否可以在准备好的 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屋!