问题描述
我的查询抛出此错误.谁能看到原因?
My query is throwing up this error. Can anyone see why?
$query = "SELECT * FROM Units WHERE ID = `$uniqueUnits[a]`";
推荐答案
两个问题.
-
您正在使用反引号分隔字符串.反引号分隔字段,因此MySQL认为您正在尝试为其指定列名称.
You're using backticks to delimit a string. Backticks delimit fields, so MySQL thinks you're trying to give it a column name.
该错误消息表示,实际上,它认为它是列名的该值是空的.因此,您的值$uniqueUnits[a]
可能已损坏,或未正确插值.
The error message indicates that, in fact, this value that it thinks is a column name, is empty. So your value $uniqueUnits[a]
is probably broken, or not being interpolated correctly.
您应该执行以下操作:
-
使用复杂语法"明确插入变量 ,以确保字符串格式正确;
Interpolate your variables explictly with the "complex syntax" to be sure that the string forms properly;
检查 $query
的值,以便您查看正在发生的情况:
Check the value of $query
so that you can see what's going on:
print $query;
使用实际的引号分隔字符串:
Use actual quotation marks to delimit strings:
$query = "SELECT * FROM Units WHERE ID = '{$uniqueUnits[a]}'";
// ^ quote
// ^ PHP variable interpolation
这篇关于"where子句"中的未知列“"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!