protected function selectDatabase() {
        if ($this->database !== null) {
            try {
                mysql_select_db($this->database, $this->hConnection) || trigger_error(mysql_error($this->hConnection), E_USER_ERROR);
            }
            catch (\Exception $ex) {
                $ex = new DatabaseException($ex->getMessage(), mysql_errno($this->hConnection), $ex);
                throw $ex->addMessage('Can not select database "'.$this->database.'"');
            }
        }
        return $this;
    }