CodeIgniter单个更新查询使用现有列数据更新一列?

chr*_*ris 16 php mysql activerecord codeigniter

在我的数据库中,我有一个日期时间的Last和Current列.只是为了留意有人上次使用有效登录我正在建立的服务.

我想知道的是,是否可以使用该行中的另一列更新行上的一列,同时更新另一列

即:将Last设置为当前Current,然后将Current设置为当前的日期?

有道理吗?

Raj*_*jan 49

试试这样..

$data=array('current_login'=>date('Y-m-d H:i:s'));
$this->db->set('last_login','current_login',false);
$this->db->where('id','some_id');
$this->db->update('login_table',$data);
Run Code Online (Sandbox Code Playgroud)

上面代码生成的查询: -

UPDATE login_tableSET last_login = current_login,current_login='2018-01-18 15:24:13'WHERE id='some_id'