Don*_*chr 3 mysql sql coldfusion
好.每当我尝试在其中获得多个WHERE条件时,它只会给我一个SQL语法错误.
错误:
Error Executing Database Query.
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 'read = '0'' at line 3
Resources:
Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debug Output Settings, and select the Robust Exception Information option.
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.
Browser Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
Remote Address ::1
Referrer
Date/Time 21-Oct-14 08:27 PM
Run Code Online (Sandbox Code Playgroud)
SQL查询本身:
<cfquery name = "getUserAlerts" datasource = "#DSN#">
SELECT *
FROM user_alerts
WHERE client_id = '#clientUser.id#'
AND read = '0'
</cfquery>
Run Code Online (Sandbox Code Playgroud)
在我看来,SQL查询没有任何问题.它应该工作,是否有人可以看到我写的错误?或者可以给出修复?
提前致谢!
编辑:
谢谢你给我的快速答案.反推功用了!多谢你们!
错误可能是因为这READ是一个保留字.完全重命名列(首选)或使用反引号将其转义.
另外,您应该使用cfqueryparam所有变量查询参数.CFQueryparam提供了许多好处(数据类型检查,提高查询性能等).其中一个最重要的是帮助防止sql注入,即使使用带引号的字符串也可能是一个问题.