用laravel 框架想實(shí)現(xiàn)一個(gè)分頁(yè)接口,返回?cái)?shù)據(jù)表中其中一部分字段
$list = DB::table('booklist_table')->orderBy('create_time','asc')->paginate($size,['id','title','author','image'])->toJson();
return json_decode($list,true);
結(jié)果運(yùn)行報(bào)錯(cuò)
"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 ' `title`, `author`, `image`) as aggregate from `booklist_table`' at line 1 (SQL: select count(`id`, `title`, `author`, `image`) as aggregate from `booklist_table`) ◀"
后來(lái)經(jīng)過(guò)查詢?cè)驅(qū)⒋a改為
$list = DB::table('booklist_table')->select('id','title','author','image')->orderBy('create_time','asc')->paginate($size)->toJson();
結(jié)果正確!
以上這篇laravel 解決paginate查詢多個(gè)字段報(bào)錯(cuò)的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- laravel 執(zhí)行遷移回滾示例
- Laravel 5框架學(xué)習(xí)之?dāng)?shù)據(jù)庫(kù)遷移(Migrations)
- Laravel5.5 數(shù)據(jù)庫(kù)遷移:創(chuàng)建表與修改表示例
- laravel解決遷移文件一次刪除創(chuàng)建字段報(bào)錯(cuò)的問(wèn)題