加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 21:57:43 所属栏目:PHP教程 来源:网络整理
导读:我一直在 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 '
我一直在

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')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读