type = DatabaseType::MYSQL; $this->grammar = new MysqlGrammar(); $this->schemaGrammar = new MysqlSchemaGrammar(); $this->connect($dbdata); } /** * {@inheritdoc} */ public function connect(array $dbdata = null) /* : void */ { $this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata; if(!isset($this->dbdata['db'])) { throw new InvalidConnectionConfigException('db'); } if(!isset($this->dbdata['host'])) { throw new InvalidConnectionConfigException('host'); } if(!isset($this->dbdata['port'])) { throw new InvalidConnectionConfigException('port'); } if(!isset($this->dbdata['database'])) { throw new InvalidConnectionConfigException('database'); } if(!isset($this->dbdata['login'])) { throw new InvalidConnectionConfigException('login'); } if(!isset($this->dbdata['password'])) { throw new InvalidConnectionConfigException('password'); } $this->close(); $this->prefix = $dbdata['prefix'] ?? ''; try { $this->con = new \PDO($this->dbdata['db'] . ':host=' . $this->dbdata['host'] . ':' . $this->dbdata['port'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8', $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) { $this->status = DatabaseStatus::MISSING_DATABASE; $this->con = null; } finally { $this->dbdata['password'] = '****'; } } }