AbcAeffchen AbcAeffchen - 10 days ago 6
PHP Question

Using one parameter multiple times in prepared mysqli-statement

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);


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

Answer

Just to close the question:

The answer is no.

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.