From: skodak Date: Mon, 9 Jun 2008 20:22:11 +0000 (+0000) Subject: MDL-15194 adodb separation, dml database creation support X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e4c033a9dd7762e6d4d372a5649e63630b5acfa8;p=moodle.git MDL-15194 adodb separation, dml database creation support --- diff --git a/admin/cliupgrade.php b/admin/cliupgrade.php index a46ab6264b..e17821cbea 100644 --- a/admin/cliupgrade.php +++ b/admin/cliupgrade.php @@ -464,6 +464,7 @@ if (!file_exists(dirname(dirname(__FILE__)) . '/config.php')) { $errormsg = get_string('dbwronghostserver', 'install'); } +error('fix cml installer'); //TODO: fix cli installer if (empty($errormsg)) { /// Have the $db object ready because we are going to use it often diff --git a/install.php b/install.php index c0b511e101..dbece00c0d 100644 --- a/install.php +++ b/install.php @@ -320,19 +320,11 @@ if ($INSTALL['stage'] == DATABASE) { error_reporting(0); // Hide errors if (! $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix'])) { - $db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609 - if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB - switch ($INSTALL['dbtype']) { /// Try to create a database - case 'mysql': - case 'mysqli': - if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) { - $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']); - } else { - $errormsg = get_string('dbcreationerror', 'install'); - $nextstage = DATABASE; - } - break; - } + if (!$DB->create_database($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'])) { + $errormsg = get_string('dbcreationerror', 'install'); + $nextstage = DATABASE; + } else { + $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']); } } else { // TODO: db encoding checks ?? @@ -651,7 +643,7 @@ if ($nextstage == SAVE) { //==========================================================================// function form_table($nextstage, $formaction, $databases) { - global $INSTALL, $db; + global $INSTALL; /// Print the standard form if we aren't in the DOWNLOADLANG page /// because it has its own form. diff --git a/lib/dml/adodb_moodle_database.php b/lib/dml/adodb_moodle_database.php index 41bfad660f..3ab3a0d900 100644 --- a/lib/dml/adodb_moodle_database.php +++ b/lib/dml/adodb_moodle_database.php @@ -61,8 +61,6 @@ abstract class adodb_moodle_database extends moodle_database { $this->db = ADONewConnection($this->get_dbtype()); - global $db; $db = $this->db; // TODO: BC only for now - // See MDL-6760 for why this is necessary. In Moodle 1.8, once we start using NULLs properly, // we probably want to change this value to ''. $this->db->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \''; diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 40b6b0026d..7593d5ffb3 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -108,6 +108,19 @@ abstract class moodle_database { */ public abstract function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null); + /** + * Attempt to create the database + * @param string $dbhost + * @param string $dbuser + * @param string $dbpass + * @param string $dbname + * + * @return bool success + */ + public function create_database($dbhost, $dbuser, $dbpass, $dbname) { + return false; + } + /** * Close database connection and release all resources * and memory (especially circular memory references). diff --git a/lib/dml/mysqli_adodb_moodle_database.php b/lib/dml/mysqli_adodb_moodle_database.php index 9b4280b5a7..176a109776 100644 --- a/lib/dml/mysqli_adodb_moodle_database.php +++ b/lib/dml/mysqli_adodb_moodle_database.php @@ -9,6 +9,27 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php'); */ class mysqli_adodb_moodle_database extends adodb_moodle_database { + /** + * Attempt to create the database + * @param string $dbhost + * @param string $dbuser + * @param string $dbpass + * @param string $dbname + * + * @return bool success + */ + public function create_database($dbhost, $dbuser, $dbpass, $dbname) { + $this->db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609 + if ($this->db->Connect($dbhost, $dbuser, $dbpass)) { /// Try to connect without DB + if ($this->db->Execute("CREATE DATABASE $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci")) { + $this->db->Disconnect(); + return true; + } else { + return false; + } + } + } + /** * Detects if all needed PHP stuff installed. * Do not connect to connect to db if this test fails. diff --git a/lib/dmllib.php b/lib/dmllib.php index 5e599fe346..f542ae4bd7 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -37,8 +37,6 @@ /// GLOBAL CONSTANTS ///////////////////////////////////////////////////////// -require_once($CFG->libdir.'/dmllib_todo.php'); - /** * Bitmask, indicates only :name type parameters are supported by db backend. */ diff --git a/lib/setup.php b/lib/setup.php index 457cd70118..07c20fa687 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -53,11 +53,6 @@ global $MCACHE; * @global object(course) $COURSE */ global $COURSE; -/** - * Legacy definition of db type TODO: remove in 2.0 - * @global object(db) $db - */ -global $db; /** * Database instances * @global object(mdb) $DB diff --git a/lib/simpletest/testbackuplib.php b/lib/simpletest/testbackuplib.php index 941a5ddfa5..5964631921 100644 --- a/lib/simpletest/testbackuplib.php +++ b/lib/simpletest/testbackuplib.php @@ -44,7 +44,6 @@ class backuplib_test extends UnitTestCase { var $real_dataroot; var $rs; var $firstcolumn; - var $db; var $testfiles = array(); var $userbasedir;