HyeonJunOh
HyeonJunOh

Reputation: 764

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.

Upvotes: 4

Views: 4743

Answers (2)

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

Hope it helps.

Upvotes: 0

Ivanka Todorova
Ivanka Todorova

Reputation: 10219

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

Upvotes: 7

Related Questions