本文介绍了添加一个条款,到MySQL的语句,而无需使用codeIgniter的活动记录功能报价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在codeigniter使用活动记录,以更新行,我只想增加一个字段值(received_qty = received_qty +1),我意识到,我可以做,在通常的SQL,但我不能在codeigniter的活动记录

I wanted to update a row using active records in codeigniter, and I only want to increment a field value (received_qty = received_qty +1) , I realized that I can do that in usual sql, but I cant in codeigniter active records

$update['received_qty'] = 'received_qty + 1';
$update['received_date'] = date("Y-m-d");
$this->db->where($where);
$this->db->update('vrs_distribution', $update);

谁知道如何使用活动记录去做呢?

anyone know how to do it using active records?

推荐答案

这会工作。

$this->db->set('received_qty', 'received_qty + 1', FALSE);
$this->db->set('received_date', date("Y-m-d"));
$this->db->where($where);
$this->db->update('vrs_distribution');

ActiveRecord的逃逸一切摆成一组(),其中()和许多其他的方法。在哪里,设置既可以利用$一个可选的第三个参数逃脱这是一个布尔值。它设置为false,codeIgniter不会逃避任何东西,这意味着你的领域增量不会被视为一个字符串。

ActiveRecord escapes everything put into a set(), where() and many other methods. Where and set can both take an optional third parameter of $escape which is a boolean. Set it to FALSE and CodeIgniter will not escape anything, meaning your field increment wont be treated as a string.

这篇关于添加一个条款,到MySQL的语句,而无需使用codeIgniter的活动记录功能报价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:06