MySQL 数据库中的 PDOException 错误


PDOException error in MySQL database

>我在执行查询时收到以下错误消息

[2/2] DBALException: An exception occurred while executing 'SELECT DISTINCT s0_.id AS id0, s0_. AS 1 FROM shop s0_ WHERE s0_.isLocked = ? ORDER BY s0_.owner_id DESC LIMIT 20 OFFSET 0' with params [0]:
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 'AS 1 FROM shop s0_ WHERE s0_.isLocked = 0 ORDER BY s0_.owner_' at line 1   +
[1/2] PDOException: 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 'AS 1 FROM shop s0_ WHERE s0_.isLocked = 0 ORDER BY s0_.owner_' at line 1  

这应该是查询错误还是其他错误?因为似乎我的查询是合法的。

SELECT DISTINCT s0_.id AS id0, s0_. AS 1

这应该是一个查询错误。您正在从表s0_和没有同一表名称的字段中选择唯一 id,但字段不能没有名称。

您应该添加一个字段名称,如下所示:

SELECT DISTINCT s0_.id AS id0, s0_.FIELDNAME AS `1`
SELECT DISTINCT s0_.id AS id0, s0_. AS `1`

将 1 包装在"中

以及上面评论中缺少的字段名称...