CI_DB_pdo_driver::_update_batch PHP Method

_update_batch() protected method

Generates a platform-specific batch update string from the supplied data
protected _update_batch ( string $table, array $values, string $index ) : string
$table string Table name
$values array Update data
$index string WHERE key
return string
    protected function _update_batch($table, $values, $index)
    {
        $ids = array();
        foreach ($values as $key => $val) {
            $ids[] = $val[$index];
            foreach (array_keys($val) as $field) {
                if ($field !== $index) {
                    $final[$field][] = 'WHEN ' . $index . ' = ' . $val[$index] . ' THEN ' . $val[$field];
                }
            }
        }
        $cases = '';
        foreach ($final as $k => $v) {
            $cases .= $k . ' = CASE ' . "\n";
            foreach ($v as $row) {
                $cases .= $row . "\n";
            }
            $cases .= 'ELSE ' . $k . ' END, ';
        }
        $this->where($index . ' IN(' . implode(',', $ids) . ')', NULL, FALSE);
        return 'UPDATE ' . $table . ' SET ' . substr($cases, 0, -2) . $this->_compile_wh('qb_where');
    }