define('MAX_COURSES_IN_CATEGORY', 10000); // MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES must not be more than max integer!
define('MAX_COURSE_CATEGORIES', 10000);
-/**
- * Sets up global $DB moodle_database instance
- * @return void
- */
-function setup_DB() {
- global $CFG, $DB;
-
- if (isset($DB)) {
- return;
- }
-
- if (!isset($CFG->dbuser)) {
- $CFG->dbuser = '';
- }
-
- if (!isset($CFG->dbpass)) {
- $CFG->dbpass = '';
- }
-
- if (!isset($CFG->dbname)) {
- $CFG->dbname = '';
- }
-
- if (!isset($CFG->dbpersist)) {
- $CFG->dbpersist = false;
- }
-
- if (!isset($CFG->dblibrary)) {
- $CFG->dblibrary = 'adodb';
- }
-
- if (!isset($CFG->dboptions)) {
- $CFG->dboptions = array();
- }
-
- $classname = $CFG->dbtype.'_'.$CFG->dblibrary.'_moodle_database';
- require_once($CFG->libdir.'/dml/'.$classname.'.php');
- $DB = new $classname();
-
- $CFG->dbfamily = $DB->get_dbfamily(); // TODO: BC only for now
-
- $driverstatus = $DB->driver_installed();
-
- if ($driverstatus !== true) {
- print_error('dbdriverproblem', 'error', '', $driverstatus);
- }
-
- if (debugging('', DEBUG_ALL)) {
- // catch errors
- ob_start();
- } else {
- $prevdebug = error_reporting(0);
- }
- if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix, $CFG->dboptions)) {
- if (debugging('', DEBUG_ALL)) {
- if ($dberr = ob_get_contents()) {
- $dberr = '<p><em>'.$dberr.'</em></p>';
- }
- ob_end_clean();
- } else {
- $dberr = '';
- }
- if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
- if (file_exists($CFG->dataroot.'/emailcount')){
- $fp = fopen($CFG->dataroot.'/emailcount', 'r');
- $content = fread($fp, 24);
- fclose($fp);
- if((time() - (int)$content) > 600){
- @mail($CFG->emailconnectionerrorsto,
- 'WARNING: Database connection error: '.$CFG->wwwroot,
- 'Connection error: '.$CFG->wwwroot);
- $fp = fopen($CFG->dataroot.'/emailcount', 'w');
- fwrite($fp, time());
- }
- } else {
- @mail($CFG->emailconnectionerrorsto,
- 'WARNING: Database connection error: '.$CFG->wwwroot,
- 'Connection error: '.$CFG->wwwroot);
- $fp = fopen($CFG->dataroot.'/emailcount', 'w');
- fwrite($fp, time());
- }
- }
- print_error('dbconnectionfailed', 'error', '', $dberr);
- }
- if (debugging('', DEBUG_ALL)) {
- ob_end_clean();
- } else {
- error_reporting($prevdebug);
- }
-
- return true;
-}
-
/// Some constants
define('LASTACCESS_UPDATE_SECS', 60); /// Number of seconds to wait before
/// updating lastaccess information in DB.
<?php //$Id$
require_once($CFG->libdir.'/dml/database_column_info.php');
+require_once($CFG->libdir.'/dml/moodle_recordset.php');
/// GLOBAL CONSTANTS /////////////////////////////////////////////////////////
}
/**
- * Loads and returns a driver instance with the specified type and library.
+ * Loads and returns a database instance with the specified type and library.
* @param string $type database type of the driver (mysql, postgres7, mssql, etc)
- * @param string $library database library of the driver (adodb, pdo, etc)
- * @return moodle_database driver object
+ * @param string $library database library of the driver (adodb, pdo, native, etc)
+ * @return moodle_database driver object or null if error
*/
- public static function get_driver($type, $library = 'adodb') {
+ public static function get_driver_instance($type, $library) {
global $CFG;
- $classname = $type . '_' . $library . '_moodle_database';
- require_once ("$CFG->libdir/dml/$classname.php");
- return new $classname ();
+
+ $classname = $type.'_'.$library.'_moodle_database';
+ $libfile = "$CFG->libdir/dml/$classname.php";
+
+ if (!file_exists($libfile)) {
+ return null;
+ }
+
+ require_once($libfile);
+ return new $classname();
}
/**
/// http://docs.moodle.org/en/DML_functions
/// (feel free to modify, improve and document such page, thanks!)
+require_once($CFG->libdir.'/dml/moodle_database.php');
+
+/**
+ * Sets up global $DB moodle_database instance
+ * @return void
+ */
+function setup_DB() {
+ global $CFG, $DB;
+
+ if (isset($DB)) {
+ return;
+ }
+
+ if (!isset($CFG->dbuser)) {
+ $CFG->dbuser = '';
+ }
+
+ if (!isset($CFG->dbpass)) {
+ $CFG->dbpass = '';
+ }
+
+ if (!isset($CFG->dbname)) {
+ $CFG->dbname = '';
+ }
+
+ if (!isset($CFG->dbpersist)) {
+ $CFG->dbpersist = false;
+ }
+
+ if (!isset($CFG->dblibrary)) {
+ $CFG->dblibrary = 'adodb';
+ }
+
+ if (!isset($CFG->dboptions)) {
+ $CFG->dboptions = array();
+ }
+
+ $DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
+
+ $CFG->dbfamily = $DB->get_dbfamily(); // TODO: BC only for now
+
+ $driverstatus = $DB->driver_installed();
+
+ if ($driverstatus !== true) {
+ print_error('dbdriverproblem', 'error', '', $driverstatus);
+ }
+
+ if (debugging('', DEBUG_ALL)) {
+ // catch errors
+ ob_start();
+ } else {
+ $prevdebug = error_reporting(0);
+ }
+ if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix, $CFG->dboptions)) {
+ if (debugging('', DEBUG_ALL)) {
+ if ($dberr = ob_get_contents()) {
+ $dberr = '<p><em>'.$dberr.'</em></p>';
+ }
+ ob_end_clean();
+ } else {
+ $dberr = '';
+ }
+ if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
+ if (file_exists($CFG->dataroot.'/emailcount')){
+ $fp = fopen($CFG->dataroot.'/emailcount', 'r');
+ $content = fread($fp, 24);
+ fclose($fp);
+ if((time() - (int)$content) > 600){
+ @mail($CFG->emailconnectionerrorsto,
+ 'WARNING: Database connection error: '.$CFG->wwwroot,
+ 'Connection error: '.$CFG->wwwroot);
+ $fp = fopen($CFG->dataroot.'/emailcount', 'w');
+ fwrite($fp, time());
+ }
+ } else {
+ @mail($CFG->emailconnectionerrorsto,
+ 'WARNING: Database connection error: '.$CFG->wwwroot,
+ 'Connection error: '.$CFG->wwwroot);
+ $fp = fopen($CFG->dataroot.'/emailcount', 'w');
+ fwrite($fp, time());
+ }
+ }
+ print_error('dbconnectionfailed', 'error', '', $dberr);
+ }
+ if (debugging('', DEBUG_ALL)) {
+ ob_end_clean();
+ } else {
+ error_reporting($prevdebug);
+ }
+
+ return true;
+}
/// Load up standard libraries
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
+ require_once($CFG->libdir .'/dmllib.php'); // Database access
require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
require_once($CFG->libdir .'/accesslib.php'); // Access control functions
require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
if (is_null(grade_test::$db)) {
$this->realdb = $DB;
- grade_test::$db = moodle_database::get_driver($CFG->dbtype, $CFG->dblibrary);
+ grade_test::$db = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
grade_test::$db->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, "tst_", $CFG->dboptions);
}