$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
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 ??
//==========================================================================//
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.
$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. \'';
*/
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).
*/
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.
/// GLOBAL CONSTANTS /////////////////////////////////////////////////////////
-require_once($CFG->libdir.'/dmllib_todo.php');
-
/**
* Bitmask, indicates only :name type parameters are supported by db backend.
*/
* @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
var $real_dataroot;
var $rs;
var $firstcolumn;
- var $db;
var $testfiles = array();
var $userbasedir;