php – 按字段排序SQL状态异常1064

我一直在

exception 'PDOException' with message 'sqlSTATE[42000]: 
Syntax error or access violation: 1064 
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 
'(questionid,'sfname','slname','school','grade','addr','city','state' at line 1'

从这个声明:

$stmt = $db->prepare('SELECT * FROM event_responses WHERE eventid= :eventid ORDER BY userid DESC,field (questionid,\''.implode("','",$columns1).'\')');

我回应了里面的声明,它对我来说很好看:

SELECT *
FROM event_responses
WHERE eventid= :eventid
ORDER BY userid DESC,'state','zip','semail','sphone','pfname','plname','pemail','pphone','noattend','regid','submitDate','attended','regmethod')

为什么会这样?

解决方法

你在MysqL中遇到了一个奇怪的问题:

Note

By default,there must be no whitespace between a function name and
the parenthesis following it. This helps the MysqL parser distinguish
between function calls and references to tables or columns that happen
to have the same name as a function. However,spaces around function
arguments are permitted.

删除字段后的空格,使表达式为:

SELECT *
FROM event_responses
WHERE eventid = :eventid
ORDER BY userid DESC,field(questionid,'regmethod')

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...