Is it possible in MySQL to use the PREPARE command with named parameters such as PDO
in PHP:
Here is my example:
SET @s = 'SELECT * FROM MY_TABLE WHERE my_column_1 = ? AND my_column_2 = ? ';
PREPARE stmt2 FROM @s;
SET @a = 54;
SET @b = 89';
EXECUTE stmt2 USING @a, @b;
Is it possible to do something like that :
SET @s = 'SELECT * FROM MY_TABLE WHERE my_column_1 = :value1 AND my_column_2 = :value2 ';
I suggest looking at the documentation regarding this. https://dev.mysql.com/doc/refman/8.0/en/prepare.html
The documentation makes no references to any other way to bind variables other than the ?
s, but it does mention that you can use user defined variables.
SET @s = 'SELECT * FROM MY_TABLE WHERE my_column_1 = @a AND my_column_2 = @b ';
PREPARE stmt2 FROM @s;
SET @a = 54;
SET @b = 89';
EXECUTE stmt2;
Produces the same output and the variables are only evaluated at execution of the statement, it just lacks the explicitness of binding the variable to the query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With