我在db中的给定字段上尝试增加1时出现问题.我尝试了有无活动记录.
我的函数看起来像这样(在我的模型中)
function _set_reads($id){
$this->db->set('reads', 'reads+1', FALSE)
$this->db->where('id', $id);
$this->db->update('article');
}
Run Code Online (Sandbox Code Playgroud)
和
function _set_reads($id){
$sql = 'update article set reads=reads+1 where id=?';
$this->db->query($sql, array($id));
}
Run Code Online (Sandbox Code Playgroud)
我在两种情况下都得到相同的错误,它是以下错误消息:
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 'reads+1 WHERE `id` = '15'' at line 1
UPDATE `article` SET `reads` = reads+1 WHERE `id` = '15'
Run Code Online (Sandbox Code Playgroud)
我使用的是最新版本的MAMP