DBServer::Save PHP Method

Save() public method

public Save ( )
    function Save()
    {
        $row = $this->Unbind();
        unset($row['server_id']);
        unset($row['id']);
        // Prepare SQL statement
        $set = [];
        $bind = [];
        foreach ($row as $field => $value) {
            $set[] = "`{$field}` = ?";
            $bind[] = $value;
        }
        $set = join(', ', $set);
        try {
            if ($this->dbId) {
                // Perform Update
                $bind[] = $this->dbId;
                $this->Db->Execute("UPDATE servers SET {$set} WHERE id = ?", $bind);
            } else {
                // Perform Insert
                $this->Db->Execute("INSERT INTO servers SET {$set}", $bind);
                $this->dbId = $this->Db->Insert_ID();
            }
        } catch (Exception $e) {
            throw new Exception("Cannot save server. Error: " . $e->getMessage(), $e->getCode());
        }
    }

Usage Example

 public function ResumeServer(\DBServer $DBServer)
 {
     if ($this->getResumeStrategy() == \Scalr_Role_Behavior::RESUME_STRATEGY_INIT) {
         $DBServer->status = \SERVER_STATUS::PENDING;
     }
     $DBServer->SetProperty(\SERVER_PROPERTIES::RESUMING, 1);
     $DBServer->dateAdded = date("Y-m-d H:i:s");
     $DBServer->Save();
 }