/** * getDsn * * @param string $driver * * @return array|bool */ public static function getDsn($driver) { $const = 'WINDWALKER_TEST_DB_DSN_' . strtoupper($driver); // First let's look to see if we have a DSN defined or in the environment variables. if (defined($const) || getenv($const)) { $dsn = defined($const) ? constant($const) : getenv($const); } else { return false; } return PdoHelper::extractDsn($dsn); }
/** * connect * * @throws \RuntimeException * @return static */ public function connect() { if ($this->connection) { return $this; } $dsn = PdoHelper::getDsn($this->options['driver'], $this->options); try { $this->connection = new \PDO($dsn, $this->options['user'], $this->options['password'], $this->options['driverOptions']); } catch (\PDOException $e) { throw new \RuntimeException('Could not connect to PDO: ' . $e->getMessage() . '. DSN: ' . $dsn, $e->getCode(), $e); } $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); return $this; }