Skip to content

Commit

Permalink
MDL-15194 adodb separation, dml database creation support
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 9, 2008
1 parent 245ac55 commit e4c033a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions admin/cliupgrade.php
Expand Up @@ -464,6 +464,7 @@
$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
Expand Down
20 changes: 6 additions & 14 deletions install.php
Expand Up @@ -320,19 +320,11 @@
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 ??
Expand Down Expand Up @@ -651,7 +643,7 @@
//==========================================================================//

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.
Expand Down
2 changes: 0 additions & 2 deletions lib/dml/adodb_moodle_database.php
Expand Up @@ -61,8 +61,6 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix,

$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. \'';
Expand Down
13 changes: 13 additions & 0 deletions lib/dml/moodle_database.php
Expand Up @@ -108,6 +108,19 @@ public abstract function export_dbconfig();
*/
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).
Expand Down
21 changes: 21 additions & 0 deletions lib/dml/mysqli_adodb_moodle_database.php
Expand Up @@ -9,6 +9,27 @@
*/
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.
Expand Down
2 changes: 0 additions & 2 deletions lib/dmllib.php
Expand Up @@ -37,8 +37,6 @@

/// GLOBAL CONSTANTS /////////////////////////////////////////////////////////

require_once($CFG->libdir.'/dmllib_todo.php');

/**
* Bitmask, indicates only :name type parameters are supported by db backend.
*/
Expand Down
5 changes: 0 additions & 5 deletions lib/setup.php
Expand Up @@ -53,11 +53,6 @@
* @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
Expand Down
1 change: 0 additions & 1 deletion lib/simpletest/testbackuplib.php
Expand Up @@ -44,7 +44,6 @@ class backuplib_test extends UnitTestCase {
var $real_dataroot;
var $rs;
var $firstcolumn;
var $db;
var $testfiles = array();
var $userbasedir;

Expand Down

0 comments on commit e4c033a

Please sign in to comment.