From fa648098b2d8c99dea7671a8ba3aaeae7f5e6f11 Mon Sep 17 00:00:00 2001 From: poltawski Date: Sat, 27 Jun 2009 21:22:27 +0000 Subject: [PATCH] dml/sqllite MDL-19642 - Make connections more robust - Include 'pdo' as an extension to be checked for - Bail out of a connect and throw an exception if the required extensions aren't loaded - Don't ignore pdo exceptions on connect error - throw our own exception --- lib/dml/pdo_moodle_database.php | 9 ++++++++- lib/dml/sqlite3_pdo_moodle_database.php | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/dml/pdo_moodle_database.php b/lib/dml/pdo_moodle_database.php index dd735ccdb0..46443e0475 100644 --- a/lib/dml/pdo_moodle_database.php +++ b/lib/dml/pdo_moodle_database.php @@ -57,9 +57,15 @@ abstract class pdo_moodle_database extends moodle_database { * @return bool success */ public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) { + $driverstatus = $this->driver_installed(); + + if ($driverstatus !== true) { + throw new dml_exception('dbdriverproblem', $driverstatus); + } + $this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions); - try { + try{ $this->pdb = new PDO($this->get_dsn(), $this->dbuser, $this->dbpass, $this->get_pdooptions()); // generic PDO settings to match adodb's default; subclasses can change this in configure_dbconnection $this->pdb->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); @@ -67,6 +73,7 @@ abstract class pdo_moodle_database extends moodle_database { $this->configure_dbconnection(); return true; } catch (PDOException $ex) { + throw new dml_connection_exception($ex->getMessage()); return false; } } diff --git a/lib/dml/sqlite3_pdo_moodle_database.php b/lib/dml/sqlite3_pdo_moodle_database.php index 2e9cd0cb01..e3821cc723 100644 --- a/lib/dml/sqlite3_pdo_moodle_database.php +++ b/lib/dml/sqlite3_pdo_moodle_database.php @@ -38,8 +38,9 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database { * @return mixed true if ok, string if something */ public function driver_installed() { - if (!extension_loaded('pdo_sqlite')) + if (!extension_loaded('pdo_sqlite') || !extension_loaded('pdo')){ return get_string('sqliteextensionisnotpresentinphp', 'install'); + } return true; } -- 2.39.5