MySQL查询中输入参数的语法 [英] Syntax for input parameters in a MySQL query

查看:229
本文介绍了MySQL查询中输入参数的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近将数据库从MSSQL切换到了MySQL,使用参数的查询不再起作用.

We recently switched a database from MSSQL to MySQL and the queries that uses parameters does'nt work anymore.

这是MSSQL中的查询示例:

Here's an example of a query in MSSQL:

SELECT * FROM users u WHERE u.ID = :id

通常,参数浏览器会弹出并要求我提供:id的值,但是在MySQL中,我会收到此错误:

Normally, the parameter browser would popup and ask me for a value for :id, but in MySQL I get this error :

您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以在':id'

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':id'

我尝试使用@或?而不是:,它不起作用.

I tried using a @ or ? instead of : and it does'nt work.

预先感谢您的帮助.

推荐答案

语法不相同

set @id:=123;
SELECT * FROM users u WHERE u.ID = @id;

用户定义变量的文档

这篇关于MySQL查询中输入参数的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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