MySQL:使用 PREPARE 命令命名参数?
MySQL 中是否可以使用带有命名参数 的 PREPARE 命令,例如 PHP 中的 PDO
:
这是我的示例:
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;
是否可以这样做类似的东西:
SET @s = 'SELECT * FROM MY_TABLE WHERE my_column_1 = :value1 AND my_column_2 = :value2 ';
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 ';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议查看有关此的文档。
https://dev.mysql.com/doc/refman/8.0/ en/prepare.html
该文档没有提及除
?
之外的任何其他绑定变量的方法,但它确实提到您可以使用用户定义的变量。产生相同的输出,并且仅在执行语句时评估变量,它只是缺乏将变量绑定到查询的显式性。
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.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.