Skip to content

Commit 53fe338

Browse files
committed
Connection::getPdo() deprecated
1 parent f8b9fd3 commit 53fe338

6 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/Database/Connection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ public function getDsn(): string
9292
}
9393

9494

95+
/** @deprecated use getConnectionDriver()->getNativeConnection() */
9596
public function getPdo(): \PDO
9697
{
98+
trigger_error(__METHOD__ . '() is deprecated, use getConnectionDriver()->getNativeConnection()', E_USER_DEPRECATED);
9799
return $this->getConnectionDriver()->getNativeConnection();
98100
}
99101

src/Database/Helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ public static function loadFromFile(Connection $connection, string $file, ?calla
265265
$count = $size = 0;
266266
$delimiter = ';';
267267
$sql = '';
268-
$pdo = $connection->getPdo(); // native query without logging
268+
$driver = $connection->getConnectionDriver(); // native query without logging
269269
while (($s = fgets($handle)) !== false) {
270270
$size += strlen($s);
271271
if (!strncasecmp($s, 'DELIMITER ', 10)) {
272272
$delimiter = trim(substr($s, 10));
273273

274274
} elseif (str_ends_with($ts = rtrim($s), $delimiter)) {
275275
$sql .= substr($ts, 0, -strlen($delimiter));
276-
$pdo->exec($sql);
276+
$driver->query($sql);
277277
$sql = '';
278278
$count++;
279279
if ($onProgress) {
@@ -285,7 +285,7 @@ public static function loadFromFile(Connection $connection, string $file, ?calla
285285
}
286286

287287
if (rtrim($sql) !== '') {
288-
$pdo->exec($sql);
288+
$driver->query($sql);
289289
$count++;
290290
if ($onProgress) {
291291
$onProgress($count, isset($stat['size']) ? 100 : null);

tests/Database/Result.fetch().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test('', function () use ($connection, $driverName) {
3838
test('tests closeCursor()', function () use ($connection, $driverName) {
3939
if ($driverName === 'mysql') {
4040
$connection->query('CREATE DEFINER = CURRENT_USER PROCEDURE `testProc`(IN param int(10) unsigned) BEGIN SELECT * FROM book WHERE id != param; END;;');
41-
$connection->getPdo()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
41+
$connection->getConnectionDriver()->getNativeConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
4242

4343
$res = $connection->query('CALL testProc(1)');
4444
foreach ($res as $row) {

tests/Database/ResultSet.normalizeRow.mysql.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Assert::same(
151151
);
152152

153153

154-
$connection->getPdo()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
154+
$connection->getConnectionDriver()->getNativeConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
155155
$res = $connection->query('SELECT `int`, `decimal`, `decimal2`, `float`, `double` FROM types');
156156
Assert::equal([
157157
'int' => 1,

tests/Database/connection.option.lazy.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,28 @@ test('connect & disconnect', function () {
5757
};
5858

5959
// first connection
60-
$pdo = $connection->getPdo();
61-
$driver = $connection->getDatabaseEngine();
60+
$native = $connection->getConnectionDriver()->getNativeConnection();
61+
$driver = $connection->getConnectionDriver();
6262
Assert::same(1, $connections);
6363

6464
// still first connection
6565
$connection->connect();
66-
Assert::same($pdo, $connection->getPdo());
67-
Assert::same($driver, $connection->getDatabaseEngine());
66+
Assert::same($native, $connection->getConnectionDriver()->getNativeConnection());
67+
Assert::same($driver, $connection->getConnectionDriver());
6868
Assert::same(1, $connections);
6969

7070
// second connection
7171
$connection->reconnect();
72-
$pdo2 = $connection->getPdo();
73-
$driver2 = $connection->getDatabaseEngine();
72+
$native2 = $connection->getConnectionDriver()->getNativeConnection();
73+
$driver2 = $connection->getConnectionDriver();
7474

75-
Assert::notSame($pdo, $pdo2);
75+
Assert::notSame($native, $native2);
7676
Assert::notSame($driver, $driver2);
7777
Assert::same(2, $connections);
7878

7979
// third connection
8080
$connection->disconnect();
81-
Assert::notSame($pdo2, $connection->getPdo());
82-
Assert::notSame($driver2, $connection->getDatabaseEngine());
81+
Assert::notSame($native2, $connection->getConnectionDriver()->getNativeConnection());
82+
Assert::notSame($driver2, $connection->getConnectionDriver());
8383
Assert::same(3, $connections);
8484
});

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function connectToDB(array $options = []): Nette\Database\Explorer
4444
Tester\Environment::skip("Connection to '$args[dsn]' failed. Reason: " . $e->getMessage());
4545
}
4646

47-
$driverName = $connection->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
47+
$driverName = $connection->getConnectionDriver()->getNativeConnection()->getAttribute(PDO::ATTR_DRIVER_NAME);
4848
$cacheMemoryStorage = new Nette\Caching\Storages\MemoryStorage;
4949

5050
$structure = new Nette\Database\Structure($connection, $cacheMemoryStorage);

0 commit comments

Comments
 (0)