type = DatabaseType::SQLSRV; $this->grammar = new MysqlGrammar(); $this->schemaGrammar = new MysqlSchemaGrammar(); /** * @todo Orange-Management/phpOMS#219 * Don't automatically connect to the database during initialization. This should be done in a separate step. * This also requires to adjust some other framework code which currently expects the database connection to be established after initialization. * Sometimes DB connections may not be needed and should only be connected to once required. */ $this->connect($dbdata); } /** * {@inheritdoc} */ public function connect(array $dbdata = null) : void { $this->close(); $this->dbdata = $dbdata ?? $this->dbdata; $this->prefix = $dbdata['prefix']; if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password']) || !DatabaseType::isValidValue($this->dbdata['db']) ) { $this->status = DatabaseStatus::FAILURE; throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata)); } try { $this->con = new \PDO('sqlsrv:Server=' . $this->dbdata['host'] . ',' . $this->dbdata['port'] . ';Database=' . $this->dbdata['database'] . ';ConnectionPooling=0', $this->dbdata['login'], $this->dbdata['password']); $this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->status = DatabaseStatus::OK; } catch (\PDOException $e) { unset($this->con); $this->status = DatabaseStatus::MISSING_DATABASE; } finally { $this->dbdata['password'] = '****'; } } }