Skip to content

Commit 384ab71

Browse files
committed
Connection::getPdo() deprecated
1 parent c801ff3 commit 384ab71

5 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/Database/Connection.php

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

8181

82+
/** @deprecated use getConnectionDriver()->getNativeConnection() */
8283
public function getPdo(): \PDO
8384
{
85+
trigger_error(__METHOD__ . '() is deprecated, use getConnectionDriver()->getNativeConnection()', E_USER_DEPRECATED);
8486
return $this->getConnectionDriver()->getNativeConnection();
8587
}
8688

src/Database/Helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ public static function loadFromFile(Connection $connection, string $file, ?calla
169169
$count = $size = 0;
170170
$delimiter = ';';
171171
$sql = '';
172-
$pdo = $connection->getPdo(); // native query without logging
172+
$driver = $connection->getConnectionDriver(); // native query without logging
173173
while (($s = fgets($handle)) !== false) {
174174
$size += strlen($s);
175175
if (!strncasecmp($s, 'DELIMITER ', 10)) {
176176
$delimiter = trim(substr($s, 10));
177177

178178
} elseif (str_ends_with($ts = rtrim($s), $delimiter)) {
179179
$sql .= substr($ts, 0, -strlen($delimiter));
180-
$pdo->exec($sql);
180+
$driver->query($sql);
181181
$sql = '';
182182
$count++;
183183
if ($onProgress) {
@@ -189,7 +189,7 @@ public static function loadFromFile(Connection $connection, string $file, ?calla
189189
}
190190

191191
if (rtrim($sql) !== '') {
192-
$pdo->exec($sql);
192+
$driver->query($sql);
193193
$count++;
194194
if ($onProgress) {
195195
$onProgress($count, isset($stat['size']) ? 100 : null);

tests/Database/ResultSet.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
@@ -147,7 +147,7 @@ Assert::equal([
147147
], (array) $res->fetch());
148148

149149

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

tests/bootstrap.php

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

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

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

0 commit comments

Comments
 (0)