简体   繁体   中英

CONCAT in Update query using codeigniter

I want to update a column 'trackId' by concating columns 'id' & 'created_at'. I have tried below query but not working.

$data = array();

$data['ip'] = $ip;
$data['updated_at'] = time();
$data['trackId'] = "CONCAT(id, created_at)";

$this->db->where('id', 123)->update(MY_TABLE, $data);

Any help would be appreciated.

I got my answer. after suggestion of @Nawin.

$data = array();

$data['ip'] = $ip;
$data['updated_at'] = time();
$this->db->set('trackId', "CONCAT(id, created_at)", FALSE);

$this->db->where('id', 123)->update(MY_TABLE, $data);

It is working fine for me.

Here is my solution for update concat:

$data['ip'] = $ip;
$data['updated_at'] = time();

$this->db->where('id', 123);
$this->db->set("trackId", "CONCAT(id, created_at)", false);
$this->db->update(MY_TABLE, $data);

Can You check CONCAT rules and you should mention created_at values,

Below check this code

$data['trackId'] = "CONCAT(trackId, created_at)";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM