【问题标题】:CakePHP Pagination gives an "Limit 20 Offset 0" errorCakePHP Pagination 给出“Limit 20 Offset 0”错误
【发布时间】:2020-12-08 07:31:23
【问题描述】:

我正在尝试获取所有用户,为此我正在使用分页。

public function index()
    {
        $this->paginate = [
            'contain' => ['Groups']
        ];
        $users = $this->paginate($this->Users);

        $this->set(compact('users'));
        $this->set('_serialize', ['users']);
    }

但是在$this->paginate 之后我得到了一个

Error: 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 'groups Groups ON Groups.id = (Users.group_id) LIMIT 20 OFFSET 0' at line 1

找不到导致此问题的原因。

有人知道我为什么会遇到这个问题吗?

【问题讨论】:

    标签: php mysql sql-server cakephp pagination


    【解决方案1】:

    您必须重命名您的表格。从 v8 开始,这是保留字。您可以在此处查看有关保留字的更多详细信息:https://dev.mysql.com/doc/refman/8.0/en/keywords.html

    另一种解决方案可能是将保留字包含在 `(重音)中

    【讨论】:

    • 如果您使用在 CakePHP 的配置中启用的 identifierQuoting 选项,则会发生包装 :) 请参阅 tips
    • 这是 语法错误或访问冲突:1064 表示的。 LIMIT OFFSET 语法没有错误
    • 是的,完全正确 :) 我指出了如何使标识符引用不存在保留关键字问题的解决方案。
    • 哦,...对不起,我的错,你完全正确,很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    相关资源
    最近更新 更多