CodeIgniter-MY_Model icon indicating copy to clipboard operation
CodeIgniter-MY_Model copied to clipboard

Update increment

Open sethwhitaker opened this issue 10 years ago • 2 comments

On the docs you mention that you can do this type of update where you can increment 1 field.

$this->update(array('wins'=>'wins+1'), array('user_id' => $user_id), FALSE);

Im getting this SQL syntax error when using this currently.

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL 
server version for the right syntax to use near '20:11:14 WHERE `user_id` = 1' at line 1

UPDATE `stat` SET wins = wins+1, updated_at = 2015-12-11 20:11:14 WHERE `user_id` = 1

Filename: core/MY_Model.php

Line Number: 487

Ive tried without the optional FALSE param and I no longer get the SQL error but it just updates the field to 0 rather than incrementing it.

sethwhitaker avatar Dec 11 '15 19:12 sethwhitaker

Just wanted to check back in on this. Havent heard back about the incrementer method.

sethwhitaker avatar Jan 29 '16 17:01 sethwhitaker

Quick fix; line 506 and 558

if($this->timestamps !== FALSE) { $data[$this->_updated_at_field] = $this->_the_timestamp(); if(!$escape) $data[$this->_updated_at_field] = "'" . $data[$this->_updated_at_field] . "'"; }

rvproductions avatar Jul 31 '16 20:07 rvproductions