MDL-15194 adodb separation, dml database creation support
This commit is contained in:
@@ -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
|
||||
|
||||
+6
-14
@@ -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.
|
||||
|
||||
@@ -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. \'';
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
|
||||
/// GLOBAL CONSTANTS /////////////////////////////////////////////////////////
|
||||
|
||||
require_once($CFG->libdir.'/dmllib_todo.php');
|
||||
|
||||
/**
|
||||
* Bitmask, indicates only :name type parameters are supported by db backend.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -44,7 +44,6 @@ class backuplib_test extends UnitTestCase {
|
||||
var $real_dataroot;
|
||||
var $rs;
|
||||
var $firstcolumn;
|
||||
var $db;
|
||||
var $testfiles = array();
|
||||
var $userbasedir;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user