SQLSTATE [HY000]:常规错误:Laravel发生2053错误 [英] SQLSTATE[HY000]: General error: 2053 error occurs at Laravel
问题描述
首先,我的环境是LAMP(M代表MariaDB).
First, my environment is LAMP(M stand for MariaDB).
整个错误是:
SQLSTATE[HY000]: General error: 2053 (SQL: UPDATE Demos SET Hit = ifnull(Hit,0) + 1 WHERE id = '27')
模型中的
代码是
code in the model is
protected function IncreaseHit($id) {
DB::select('UPDATE Demos SET Hit = ifnull(Hit,0) + 1 WHERE id = \''.$id.'\'');
}
我想说的是这段代码在我的本地环境下运行良好. (本地环境为MAMP.)
What I want to say is this code works well at my local. (local environment is MAMP.)
在控制器上调用上述模型方法的代码是
And code that calls above model method at controller is
if(Cookie::get('My_Cookie_'.$id) != 'On'){
Demos::IncreaseHit($id);
Cookie::queue(Cookie::make('CS_View_'.$id, 'On',2160000));
}//Cookie Check
我找不到问题所在...请让我知道如何解决此错误.
I can't find what is wrong... Please let me know how I can fix this error.
推荐答案
使用DB::update()
:
DB::update('UPDATE Demos SET Hit = ifnull(Hit,0) + 1 WHERE id = ?', [$id]);
当没有任何内容可获取时,也会产生此错误.这样,使用DB::select()
试图从不返回任何内容的语句中获取内容.
Also this error is produced when there's nothing to fetch. That way with DB::select()
you're trying to fetch something from a statement that doesn't return anything.
文档: https://laravel.com/docs/5.2/database#running-查询
这篇关于SQLSTATE [HY000]:常规错误:Laravel发生2053错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!