type = DatabaseType::SQLSRV; $this->grammar = new SqlServerGrammar(); $this->schemaGrammar = new SqlServerSchemaGrammar(); if (isset($dbdata['datetimeformat'])) { $this->grammar->setDateTimeFormat($dbdata['datetimeformat']); $this->schemaGrammar->setDateTimeFormat($dbdata['datetimeformat']); } $this->dbdata = $dbdata; } /** * {@inheritdoc} */ public function connect(array $dbdata = null) : void { if ($this->status === DatabaseStatus::OK) { return; } $this->dbdata = $dbdata ?? $this->dbdata; 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; $this->dbdata['password'] = '****'; return; } $this->close(); 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); // Not working! $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->status = DatabaseStatus::OK; } catch (\PDOException $_) { $this->con = new NullPDO(); $this->status = DatabaseStatus::MISSING_DATABASE; } finally { $this->dbdata['password'] = '****'; } } /** * {@inheritdoc} */ public function beginTransaction() : void { $this->con->beginTransaction(); } /** * {@inheritdoc} */ public function rollBack() : void { $this->con->rollBack(); } /** * {@inheritdoc} */ public function commit() : void { $this->con->commit(); } }