php SQLSTATE[HY093]更新到Laravel 9后

vm0i2vca  于 2023-04-10  发布在  PHP
关注(0)|答案(1)|浏览(104)

我得到`SQLSTATE[HY093]:无效的参数号:绑定变量的数量与标记的数量不匹配

select * from `starters` where `dummy` != 4 and `events_id` = 11
order by `dummy` asc, time_all, (error_1 + error_2), `time_1` asc`

在将我的laravel 8项目更新到Laravel 9之后,代码是

$starters = \App\Models\Starters::where('dummy','!=', 4 )
    ->where('events_id',request()->events_id)
    ->with('events')
    ->with('drivers')
    ->with('cars')
    ->orderBy('dummy','asc')
    ->orderByRaw('time_all','asc')
    ->orderByRaw('(error_1 + error_2)','asc')
    ->orderBy('time_1','asc')->get();

看不出问题,有什么建议吗?

tf7tbtn2

tf7tbtn21#

orderByRaw()子句不能像这里一样有反引号:

->orderByRaw('(error_1 + error_2)','asc')

尝试如下操作:

$starters = \App\Models\Starters::where('dummy', '!=', 4)
    ->where('events_id', request()->events_id)
    ->with('events')
    ->with('drivers')
    ->with('cars')
    ->orderBy('dummy', 'asc')
    ->orderBy('time_all', 'asc')
    ->orderByRaw('(error_1 + error_2) asc')
    ->orderBy('time_1', 'asc')->get();

相关问题