简体   繁体   中英

SQLSTATE[HY000]: General error: 2053 error occurs at Laravel

First, my environment is LAMP(M stand for MariaDB).

Whole error is:

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.'\'');
}

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.

Use DB::update() :

DB::update('UPDATE Demos SET Hit = ifnull(Hit,0) + 1 WHERE id = ?', [$id]);

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.

Docs: https://laravel.com/docs/5.2/database#running-queries

DB::connection('my_conn')->update('UPDATE asterisk.chan_line SET sms_balance = (sms_balance-1) where id = ? ', [$value->id]);

希望能帮助到你。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM