bedezign\yii2\audit\models\AuditEntry::addBatchData PHP Method

addBatchData() public method

Writes a number of associated data records in one go.
public addBatchData ( $batchData, boolean $compact = true )
$batchData
$compact boolean
    public function addBatchData($batchData, $compact = true)
    {
        $columns = ['entry_id', 'type', 'created', 'data'];
        $rows = [];
        $params = [];
        $date = date('Y-m-d H:i:s');
        // Some database like postgres depend on the data being escaped correctly.
        // PDO can take care of this if you define the field as a LOB (Large OBject), but unfortunately Yii does threat values
        // for batch inserts the same way. This code adds a number of literals instead of the actual values
        // so that they can be bound right before insert and still get escaped correctly
        foreach ($batchData as $type => $data) {
            $param = ':data_' . str_replace('/', '_', $type);
            $rows[] = [$this->id, $type, $date, new Expression($param)];
            $params[$param] = [Helper::serialize($data, $compact), \PDO::PARAM_LOB];
        }
        static::getDb()->createCommand()->batchInsert(AuditData::tableName(), $columns, $rows)->bindValues($params)->execute();
    }