首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >语法错误或访问冲突: 1064您的SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册。

语法错误或访问冲突: 1064您的SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册。
EN

Stack Overflow用户
提问于 2022-12-03 13:40:34
回答 1查看 30关注 0票数 -1

我试图通过API存储前端的历史数据(颤振)。下面是拉拉控制器。然而,当我在postman上运行它时,出现了一个错误,列中找不到:‘字段列表’中的1054个未知列“图像”。我认为它正在检索整个用户列。从专栏中,我只看到了staff_id、date_checkIn、time_checkIn和location_checkIn。我该怎么解决这个问题?

我试过User::where('staff_id', 'date_checkIn', 'time_checkIn', 'location_checkIn')->first()->toArray();。但上面写着

语法错误或访问冲突: 1064您的SQL语法出现了错误;请检查与MariaDB服务器版本对应的手册,以获得在第1行( location_checkIn staff_id = date_checkIn限制1)附近使用“staff_id=?限制1”的正确语法……

代码语言:javascript
复制
public function userClockIn(Request $r) { 
$result = []; 
$result['status'] = false; 
$result['message'] = "something error";

$users = User::where('staff_id', $r->staff_id)->first();

// retrieve current data
$currentData = $users->toArray();

// store current data in historical data table
$historicalData = new HistoricalData();
$historicalData->fill($currentData);
$historicalData->save();

$mytime = Carbon::now();
$time = $mytime->format('H:i:s');
$date = $mytime->format('Y-m-d');

$users->date_checkIn = $date;
$users->time_checkIn = $time;
$users->location_checkIn = $r->location_checkIn;

$users->save();

$result['data'] = $users;
$result['status'] = true;
$result['message'] = "suksess add data";

return response()->json($result);
}
EN

Stack Overflow用户

回答已采纳

发布于 2022-12-03 13:52:51

要修复此错误,需要指定要从where子句的users表中检索的列。可以通过使用select方法并传入要选择的列的数组来实现这一点。

下面是一个如何更新代码以修复错误的示例:

代码语言:javascript
复制
$users = User::where('staff_id', $r->staff_id)->select(['staff_id', 'date_checkIn', 'time_checkIn', 'location_checkIn'])->first();

这只会从users表中检索指定的列,而不会导致错误。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74667272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档