4

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.

Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103
HyeonJunOh
  • 734
  • 1
  • 8
  • 22

2 Answers2

7

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

Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103
0
DB::connection('my_conn')->update('UPDATE asterisk.chan_line SET sms_balance = (sms_balance-1) where id = ? ', [$value->id]);

Hope it helps.

TMichel
  • 4,336
  • 9
  • 44
  • 67