host};dbname={$this->db_name};charset={$this->charset}"; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; try { $this->connection = new PDO($dsn, $this->username, $this->password, $options); } catch (PDOException $e) { throw new PDOException($e->getMessage(), (int)$e->getCode()); } } public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance->connection; } }