From 27ace0327382015c74e2830ff4b1c68dac930f59 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 11 Jun 2019 16:17:30 +1200 Subject: [PATCH] NEW: Deprecated PDO in favour of native drivers https://github.com/silverstripe/silverstripe-framework/issues/8598 --- _register_database.php | 35 +++++++++++++++---------------- src/Dev/Install/InstallConfig.php | 2 +- src/ORM/Connect/PDOConnector.php | 4 ++++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/_register_database.php b/_register_database.php index c7549a887..6cd40dcd0 100644 --- a/_register_database.php +++ b/_register_database.php @@ -4,24 +4,6 @@ use SilverStripe\Dev\Install\DatabaseAdapterRegistry; use SilverStripe\Dev\Install\MySQLDatabaseConfigurationHelper; - -// Register MySQL PDO as a database adapter (listed as first option in Dev/Install/config-form.html) -DatabaseAdapterRegistry::register( - array( - /** @skipUpgrade */ - 'class' => 'MySQLPDODatabase', - 'module' => 'framework', - 'title' => 'MySQL 5.0+ (using PDO)', - 'helperPath' => __DIR__ . '/src/Dev/Install/MySQLDatabaseConfigurationHelper.php', - 'helperClass' => MySQLDatabaseConfigurationHelper::class, - 'supported' => (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers())), - 'missingExtensionText' => - 'Either the PDO Extension or - the MySQL PDO Driver - are unavailable. Please install or enable these and refresh this page.' - ) -); - // Register MySQLi as a database adapter (listed as second option in Dev/Install/config-form.html) DatabaseAdapterRegistry::register( array( @@ -37,3 +19,20 @@ DatabaseAdapterRegistry::register( PHP extension is not available. Please install or enable it and refresh this page.' ) ); + +// Register MySQL PDO as a database adapter (listed as first option in Dev/Install/config-form.html) +DatabaseAdapterRegistry::register( + array( + /** @skipUpgrade */ + 'class' => 'MySQLPDODatabase', + 'module' => 'framework', + 'title' => 'MySQL 5.0+ (using PDO) - not recommended', + 'helperPath' => __DIR__ . '/src/Dev/Install/MySQLDatabaseConfigurationHelper.php', + 'helperClass' => MySQLDatabaseConfigurationHelper::class, + 'supported' => (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers())), + 'missingExtensionText' => + 'Either the PDO Extension or + the MySQL PDO Driver + are unavailable. Please install or enable these and refresh this page.' + ) +); diff --git a/src/Dev/Install/InstallConfig.php b/src/Dev/Install/InstallConfig.php index 39c3f67fa..23a2a40ed 100644 --- a/src/Dev/Install/InstallConfig.php +++ b/src/Dev/Install/InstallConfig.php @@ -20,8 +20,8 @@ class InstallConfig * @var array */ protected $preferredDatabases = [ - 'MySQLPDODatabase', 'MySQLDatabase', + 'MySQLPDODatabase', ]; public function __construct($basePath = null) diff --git a/src/ORM/Connect/PDOConnector.php b/src/ORM/Connect/PDOConnector.php index c26cc02bb..0436da200 100644 --- a/src/ORM/Connect/PDOConnector.php +++ b/src/ORM/Connect/PDOConnector.php @@ -3,6 +3,7 @@ namespace SilverStripe\ORM\Connect; use SilverStripe\Core\Config\Config; +use SilverStripe\Dev\Deprecation; use PDO; use PDOStatement; use InvalidArgumentException; @@ -135,6 +136,9 @@ class PDOConnector extends DBConnector implements TransactionManager public function connect($parameters, $selectDB = false) { + Deprecation::notice('4.5', 'Use native database drivers in favour of PDO. ' + . 'https://github.com/silverstripe/silverstripe-framework/issues/8598'); + $this->flushStatements(); // Note that we don't select the database here until explicitly