MySQL - 将数据附加到现有字段/记录的建议


MySQL - suggestions to append data to an existing field/record?

我首先将数据添加到表 events ,字段exceptions

如下
function events_exceptions($rec_id, $evt_id)
{
//$evt_id = 1;
$this->db->where('record_id', $rec_id);
$this->db->update('events', array('exceptions' => $evt_id));
}

这会给我

exceptions
1

如果我再次用$evt_id = 2运行它,我会得到

exceptions
2

等等。

我想实际将新数据附加到该字段而不是更新,所以我会有(注意逗号)

exceptions
1,2,3  //etc

我认为这可以通过调用数据库、读取行/字段的内容并通过 PHP 连接来完成 - 然后更新记录。但我想避免这样的开销。

有没有办法通过MySQL CONCAT做到这一点?

感谢您的帮助。

$query = "UPDATE table1 SET field1 = CONCAT(ifnull(field1,''),'$extra') WHERE id = '$id'";