Airship\Engine\Database::update PHP Метод

update() публичный метод

Update a row in a database table.
public update ( string $table, array $changes, array $conditions ) : mixed
$table string - table name
$changes array - associative array of which values should be assigned to each field
$conditions array - WHERE clause
Результат mixed
    public function update(string $table, array $changes, array $conditions)
    {
        if (empty($changes) || empty($conditions)) {
            return null;
        }
        $params = [];
        $queryString = "UPDATE " . $this->escapeIdentifier($table) . " SET ";
        // The first set (pre WHERE)
        $pre = [];
        foreach ($changes as $i => $v) {
            $i = $this->escapeIdentifier($i);
            if ($v === null) {
                $pre[] = " {$i} = NULL";
            } elseif ($v === true) {
                $pre[] = " {$i} = TRUE ";
            } elseif ($v === false) {
                $pre[] = " {$i} = FALSE ";
            } elseif (\is_array($v)) {
                throw new \TypeError(\trk('errors.database.array_passed'));
            } else {
                $pre[] = " {$i} = ?";
                $params[] = $v;
            }
        }
        $queryString .= \implode(', ', $pre);
        $queryString .= " WHERE ";
        // The last set (post WHERE)
        $post = [];
        foreach ($conditions as $i => $v) {
            $i = $this->escapeIdentifier($i);
            if ($v === null) {
                $post[] = " {$i} IS NULL ";
            } elseif ($v === true) {
                $post[] = " {$i} = TRUE ";
            } elseif ($v === false) {
                $post[] = " {$i} = FALSE ";
            } elseif (\is_array($v)) {
                throw new \TypeError(\trk('errors.database.array_passed'));
            } else {
                $post[] = " {$i} = ? ";
                $params[] = $v;
            }
        }
        $queryString .= \implode(' AND ', $post);
        return $this->safeQuery($queryString, $params);
    }