From: skodak Date: Fri, 21 Nov 2008 20:42:28 +0000 (+0000) Subject: MDL-17353 native drivers are now default instead of obsoleted adodb drivers X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3eae57b74eafd679be28c0b1ecffbf4243207ed8;p=moodle.git MDL-17353 native drivers are now default instead of obsoleted adodb drivers --- diff --git a/lib/dmllib.php b/lib/dmllib.php index bd6e0c6c32..a7f6a6a350 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -104,7 +104,25 @@ function setup_DB() { } if (!isset($CFG->dblibrary)) { - $CFG->dblibrary = 'adodb'; + switch ($CFG->dbtype) { + case 'postgres7' : + $CFG->dbtype = 'pgsql'; + // continue, no break here + case 'pgsql' : + $CFG->dblibrary = 'native'; + break; + + case 'mysql' : + $CFG->dbtype = 'mysqli'; + // continue, no break here + case 'mysqli' : + $CFG->dblibrary = 'native'; + break; + + default: + // the rest of drivers is not converted yet - keep adodb for now + $CFG->dblibrary = 'adodb'; + } } if (!isset($CFG->dboptions)) { @@ -116,7 +134,9 @@ function setup_DB() { } - $DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary); + if (!$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary)) { + throw new dml_exception('dbdriverproblem', "Unknown driver $CFG->dblibrary/$CFG->dbtype"); + } $CFG->dbfamily = $DB->get_dbfamily(); // TODO: BC only for now @@ -132,14 +152,21 @@ function setup_DB() { } else { $prevdebug = error_reporting(0); } - if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, $CFG->dboptions)) { + + $connected = false; + try { + $connected = $DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, $CFG->dboptions); + } Catch (Exception $e) { + $connected = false; + } + + if (!$connected) { + $dberr = ''; if (debugging('', DEBUG_ALL)) { if ($dberr = ob_get_contents()) { $dberr = '

'.$dberr.'

'; } ob_end_clean(); - } else { - $dberr = ''; } if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) { if (file_exists($CFG->dataroot.'/emailcount')){