]> git.mjollnir.org Git - moodle.git/commitdiff
dml/sqllite MDL-19642 - Make connections more robust
authorpoltawski <poltawski>
Sat, 27 Jun 2009 21:22:27 +0000 (21:22 +0000)
committerpoltawski <poltawski>
Sat, 27 Jun 2009 21:22:27 +0000 (21:22 +0000)
- 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
lib/dml/sqlite3_pdo_moodle_database.php

index dd735ccdb0a26370a1ada5ebeaa5c23c2aa2ff75..46443e047549cc24c1d1917f1ac0cb2f5c27888b 100644 (file)
@@ -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;
         }
     }
index 2e9cd0cb01534828dcec24db6368d56540bffe9c..e3821cc723cfaf82f4bdc103d365dade77642f65 100644 (file)
@@ -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;
     }