我在这里做错了什么:
<cfquery datasource="mydb" name="qCoulmnInsert">
INSERT INTO
mytable (delivered_int,unique_open_int,spamreport_int,drop_int,request_int,bounce_int,deferred_int, processed_int,date_dt,startdate_dt,enddate_dt,open_int,blocked_int)
VALUES
<!--- loop through your array --->
<cfloop from="1" to="#arrayLen(cfData)#" index="i">
(
<cfif structKeyExists(cfData[i], "delivered")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].delivered#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "unique_open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].unique_open#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "spamreport")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].unique_open#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "drop")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].drop#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "request")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].request#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "bounce")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].bounce#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "deferred")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].deferred#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "processed")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].processed#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "date")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].date#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "startdate_dt")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].startdate_dt#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "enddate_dt")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].enddate_dt#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].open#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "blocked")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].blocked#">
<cfelse>
NULL
</cfif>
)
<cfif i neq arrayLen(cfData)>,</cfif>
</cfloop>
</cfquery>
更多信息可以引用我之前的帖子:inserting structure elements into database
表结构的 SQL Fiddle:http://sqlfiddle.com/#!2/e255c/1
日期、开始和结束日期是我的数据库表中的日期时间。
错误信息:
执行数据库查询时出错。 您的 SQL 语法有误;检查与您的 MySQL 服务器版本对应的手册,了解在 '5 5 5 '2014-01-06' 10 附近使用的正确语法(第 8 行的 '2014-01-07' 3 '
The error occurred in C:\myfile.cfm: line 55
Called from C:\application.cfc: line 386
Called from C:\myfile.cfm: line 55
Called from C:\application.cfc: line 386
53 : VALUES
54 : <!--- loop through your array --->
55 : <cfloop from="1" to="#arrayLen(cfData)#" index="i">
56 : (
57 : <cfif structKeyExists(cfData[i], "delivered")>
最佳答案
查询中每个元素/列后没有逗号。
你的错误表明了这一点:
'5 5 5 '2014-01-06' 10 )
添加逗号
'5, 5, 5, '2014-01-06', 10)
这是关键问题。
关于mysql - 执行数据库查询时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21465172/