DBServer::update PHP Method

update() public method

Updates specified properties to database
public update ( array | Iterator $props )
$props array | Iterator The list of the properties to update
    public function update($props)
    {
        if (!$this->serverId) {
            throw new RuntimeException(sprintf("Server identifier has not been set in %s object yet.", get_class($this)));
        }
        $stmt = [];
        foreach ($props as $prop => $value) {
            if (!($column = array_search($prop, static::$FieldPropertyMap))) {
                throw new InvalidArgumentException(sprintf("Invalid property '%s' in the %s object.", $prop, get_class($this)));
            }
            $this->{$prop} = $value;
            $stmt[] = "`" . $column . "` = " . $this->Db->qstr($value);
        }
        if (!empty($stmt)) {
            $this->Db->Execute("\n                UPDATE `servers` SET " . join(", ", $stmt) . " WHERE `server_id`= " . $this->Db->qstr($this->serverId) . "\n            ");
        }
        return $this;
    }

Usage Example

Example #1
0
 public function ResumeServer(\DBServer $DBServer)
 {
     $DBServer->update(['status' => \SERVER_STATUS::RESUMING, 'dateAdded' => date("Y-m-d H:i:s")]);
 }