MySQL:where子句错误中的未知列 [英] MySQL: Unknown column in where clause error

查看:163
本文介绍了MySQL:where子句错误中的未知列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,由于某种原因,mysql一直将选择/插入的值视为一列.这是我的sql查询示例:

I have a PHP script and for some reason mysql keeps treating the value to select/insert as a column. Here is an example of my sql query:

$query = mysql_query("SELECT * FROM tutorial.users WHERE (uname=`".mysql_real_escape_string($username)."`)") or die(mysql_error());

结果变成:

SELECT * FROM tutorial.users WHERE (uname=`test`)

错误是:

"where"中的未知列"test" 条款"

Unknown column 'test' in 'where clause'

我也尝试过:

SELECT * FROM tutorial.users WHERE uname=`test`

推荐答案

在MySql中,反引号表示标识符是列名. (其他RDBMS为此使用括号或双引号).

In MySql, backticks indicate that an indentifier is a column name. (Other RDBMS use brackets or double quotes for this).

因此,您的查询是给我所有名为"uname"的列中的值等于名为"test"的列中的值的所有行".但是由于表中没有名为test的列,所以您会看到错误.

So your query was, "give me all rows where the value in the column named 'uname' is equal to the value in the column named 'test'". But since there is no column named test in your table, you get the error you saw.

用单引号替换反引号.

这篇关于MySQL:where子句错误中的未知列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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