Laravel- 检查与您的 MariaDB 服务器版本对应的手册,了解在第 1 行的 ') < Now()' 附近使用的正确语法
Laravel- Check the manual that corresponds to your MariaDB server version for the right syntax to use near ') < Now()' at line 1
我在使用 Laravel 执行我的程序时不断收到此错误:
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 ') < Now()' at line 1 (SQL: select count(*) as aggregate from `house` where `isoccupied` = 0 and (currentdatasync + INTERVAL '1 DAY') < Now())
我在控制器中的功能是:
public function view()
{
$failed = DB::table('house')
->where('isoccupied', 0)
->whereRaw("(currentdatasync + INTERVAL '1 DAY') < Now()")
->count('*');
return view('admin.dashboard')->with('failed', $failed);
}
我试过
return view('admin.dashboard')->with(compact($failed));
但是还是不行。
有没有人以前遇到过这种情况?
您不必使用 + INTERVAL '1 DAY'
。
尝试使用
public function view()
{
$failed = DB::table('house')
->where('isoccupied', 0)
->whereRaw("subdate(currentdatasync, 1) < Now()")
->count('*');
return view('admin.dashboard')->with('failed', $failed);
}
或者把subdate(currentdatasync, 1)
换成subdate(currentdatasync, -1)
看你需要昨天还是明天(1是昨天,-1是明天)
更新
如果你想使用 INTERVAL
像这样使用它:
public function view()
{
$failed = DB::table('house')
->where('isoccupied', 0)
->whereRaw("(`currentdatasync` + INTERVAL 1 DAY) < NOW()")
->count('*');
return view('admin.dashboard')->with('failed', $failed);
}
我在使用 Laravel 执行我的程序时不断收到此错误:
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 ') < Now()' at line 1 (SQL: select count(*) as aggregate from `house` where `isoccupied` = 0 and (currentdatasync + INTERVAL '1 DAY') < Now())
我在控制器中的功能是:
public function view()
{
$failed = DB::table('house')
->where('isoccupied', 0)
->whereRaw("(currentdatasync + INTERVAL '1 DAY') < Now()")
->count('*');
return view('admin.dashboard')->with('failed', $failed);
}
我试过
return view('admin.dashboard')->with(compact($failed));
但是还是不行。
有没有人以前遇到过这种情况?
您不必使用 + INTERVAL '1 DAY'
。
尝试使用
public function view()
{
$failed = DB::table('house')
->where('isoccupied', 0)
->whereRaw("subdate(currentdatasync, 1) < Now()")
->count('*');
return view('admin.dashboard')->with('failed', $failed);
}
或者把subdate(currentdatasync, 1)
换成subdate(currentdatasync, -1)
看你需要昨天还是明天(1是昨天,-1是明天)
更新
如果你想使用 INTERVAL
像这样使用它:
public function view()
{
$failed = DB::table('house')
->where('isoccupied', 0)
->whereRaw("(`currentdatasync` + INTERVAL 1 DAY) < NOW()")
->count('*');
return view('admin.dashboard')->with('failed', $failed);
}