|
14 | 14 | use Doctrine\DBAL\Connection; |
15 | 15 | use Doctrine\DBAL\DBALException; |
16 | 16 | use Doctrine\DBAL\Driver\ServerInfoAwareConnection; |
| 17 | +use Doctrine\DBAL\DriverManager; |
17 | 18 | use Doctrine\DBAL\Exception\TableNotFoundException; |
18 | 19 | use Doctrine\DBAL\Schema\Schema; |
19 | 20 | use Symfony\Component\Cache\Exception\InvalidArgumentException; |
@@ -370,8 +371,15 @@ protected function doSave(array $values, $lifetime) |
370 | 371 | private function getConnection() |
371 | 372 | { |
372 | 373 | if (null === $this->conn) { |
373 | | - $this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions); |
374 | | - $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
| 374 | + if (strpos($this->dsn, '://')) { |
| 375 | + if (!class_exists(DriverManager::class)) { |
| 376 | + throw new InvalidArgumentException(sprintf('Fail to parse the DSN "%s". Try running "composer require doctrine/dbal".', $this->dsn)); |
| 377 | + } |
| 378 | + $this->conn = DriverManager::getConnection(['url' => $this->dsn]); |
| 379 | + } else { |
| 380 | + $this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions); |
| 381 | + $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
| 382 | + } |
375 | 383 | } |
376 | 384 | if (null === $this->driver) { |
377 | 385 | if ($this->conn instanceof \PDO) { |
|
0 commit comments