【问题标题】:Laravel - MariaDB server version for the right syntax to use nearLaravel - MariaDB 服务器版本,用于在附近使用正确的语法
【发布时间】:2017-10-25 03:24:49
【问题描述】:

我正在尝试从天际表中查找 user_id 等于 1 的支出及其关系。

我执行的代码是:

$user_payout = Payout::fromTable('skyrim')->where('user_id',1)->with('game','cluster')->first();
        dd($user_payout);

它给了我这个错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where user_id = ? limit 1' at line 1 (SQL: select * where user_id = 1 limit 1)

为什么这不起作用?

【问题讨论】:

    标签: php mysql laravel mariadb


    【解决方案1】:

    尝试先获取数据,然后进行关系的急切加载

    $model = (new Payout)->setTable('skyrim')->where('user_id', 1)->first();
    
    if($model) {
        $model->load('game','cluster');
    }
    

    【讨论】:

    • 哈哈,第二次帮我成功了。谢谢你:)
    猜你喜欢
    • 2017-08-26
    • 2022-11-12
    • 2017-09-30
    • 2018-01-20
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    相关资源
    最近更新 更多