-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Leverage the new PDO subclasses (#6532)
| Q | A |------------- | ----------- | Type | feature | Fixed issues | N/A #### Summary This PR adds support for the new [PDO subclasses](https://wiki.php.net/rfc/pdo_driver_specific_subclasses) to DBAL.
- Loading branch information
Showing
10 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\PDO; | ||
|
||
use PDO; | ||
|
||
use const PHP_VERSION_ID; | ||
|
||
/** @internal */ | ||
trait PDOConnect | ||
{ | ||
/** @param array<int, mixed> $options */ | ||
private function doConnect( | ||
string $dsn, | ||
string $username, | ||
string $password, | ||
array $options, | ||
): PDO { | ||
// see https://github.com/php/php-src/issues/16314 | ||
if (PHP_VERSION_ID < 80400 || ($options[PDO::ATTR_PERSISTENT] ?? false) === true) { | ||
return new PDO($dsn, $username, $password, $options); | ||
} | ||
|
||
return PDO::connect($dsn, $username, $password, $options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Driver\PDO; | ||
|
||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Tests\TestUtil; | ||
use Pdo\Mysql; | ||
use Pdo\Pgsql; | ||
use Pdo\Sqlite; | ||
use PHPUnit\Framework\Attributes\RequiresPhp; | ||
|
||
#[RequiresPhp('8.4')] | ||
final class PDOSubclassTest extends FunctionalTestCase | ||
{ | ||
public function testMySQLSubclass(): void | ||
{ | ||
if (! TestUtil::isDriverOneOf('pdo_mysql')) { | ||
self::markTestSkipped('This test requires the pdo_mysql driver.'); | ||
} | ||
|
||
self::assertInstanceOf(Mysql::class, $this->connection->getNativeConnection()); | ||
} | ||
|
||
public function testPgSQLSubclass(): void | ||
{ | ||
if (! TestUtil::isDriverOneOf('pdo_pgsql')) { | ||
self::markTestSkipped('This test requires the pdo_pgsql driver.'); | ||
} | ||
|
||
self::assertInstanceOf(Pgsql::class, $this->connection->getNativeConnection()); | ||
} | ||
|
||
public function testSQLiteSubclass(): void | ||
{ | ||
if (! TestUtil::isDriverOneOf('pdo_sqlite')) { | ||
self::markTestSkipped('This test requires the pdo_sqlite driver.'); | ||
} | ||
|
||
self::assertInstanceOf(Sqlite::class, $this->connection->getNativeConnection()); | ||
} | ||
} |