Skip to content

Commit a0a76b5

Browse files
committed
Connection: the driver is created in the constructor
1 parent c91da22 commit a0a76b5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Database/Connection.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public function __construct(
5959
if (($options['newDateTime'] ?? null) === false) {
6060
$this->rowNormalizer = fn($row, $resultSet) => Helpers::normalizeRow($row, $resultSet, DateTime::class);
6161
}
62+
63+
$driver = explode(':', $dsn)[0];
64+
$class = empty($options['driverClass'])
65+
? (self::Drivers['pdo-' . $driver] ?? throw new \LogicException("Unknown PDO driver '$driver'."))
66+
: $options['driverClass'];
67+
$this->driver = new $class;
6268
}
6369

6470

@@ -77,13 +83,7 @@ public function connect(): void
7783
throw ConnectionException::from($e);
7884
}
7985

80-
$driver = explode(':', $this->dsn)[0];
81-
$class = empty($this->options['driverClass'])
82-
? (self::Drivers['pdo-' . $driver] ?? throw new \LogicException("Unknown PDO driver '$driver'."))
83-
: $this->options['driverClass'];
84-
$this->driver = new $class;
8586
$this->engine = $this->driver->createEngine();
86-
$this->preprocessor = new SqlPreprocessor($this);
8787
$this->engine->initialize($this, $this->options);
8888
Arrays::invoke($this->onConnect, $this);
8989
}
@@ -286,6 +286,7 @@ public function queryArgs(string $sql, array $params): Result
286286
public function preprocess(string $sql, ...$params): array
287287
{
288288
$this->connect();
289+
$this->preprocessor ??= new SqlPreprocessor($this);
289290
return $params
290291
? $this->preprocessor->process(func_get_args())
291292
: [$sql, []];

0 commit comments

Comments
 (0)