diff --git a/admin/index.php b/admin/index.php
index 8bcd769134afa..bdf0af2ea7617 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -94,15 +94,6 @@
print_error('withoutversion', 'debug'); // without version, stop
}
-/// Check DB prefix requirements are fulfilled
- if (empty($CFG->prefix) && $DB->get_dbfamily() != 'mysql') { //Enforce prefixes for everybody but mysql
- print_error('prefixcannotbeempty', 'debug', '', array($CFG->prefix, $CFG->dbtype));
- }
-
- if ($DB->get_dbfamily() == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
- print_error('prefixlimit', 'debug', '', $CFG->prefix);
- }
-
/// Check if the main tables have been installed yet or not.
if (!$tables = $DB->get_tables() ) { // No tables yet at all.
$maintables = false;
diff --git a/install.php b/install.php
index da36874f83ed8..5c220a064e82a 100644
--- a/install.php
+++ b/install.php
@@ -59,7 +59,7 @@
$INSTALL['dbhost'] = 'localhost';
$INSTALL['dbuser'] = '';
$INSTALL['dbpass'] = '';
- $INSTALL['dbtype'] = 'mysql';
+ $INSTALL['dbtype'] = 'mysqli_adodb';
$INSTALL['dbname'] = 'moodle';
$INSTALL['prefix'] = 'mdl_';
@@ -150,7 +150,7 @@
require_once($CFG->libdir.'/moodlelib.php');
require_once($CFG->libdir.'/weblib.php');
require_once($CFG->libdir.'/deprecatedlib.php');
-require_once($CFG->libdir.'/adodb/adodb.inc.php');
+require_once($CFG->libdir.'/dmllib.php');
require_once($CFG->libdir.'/environmentlib.php');
require_once($CFG->libdir.'/xmlize.php');
require_once($CFG->libdir.'/componentlib.class.php');
@@ -160,10 +160,22 @@
$INSTALL['version'] = $version;
$INSTALL['release'] = $release;
-/// Have the $db object ready because we are going to use it often
-define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
-$db = &ADONewConnection($INSTALL['dbtype']);
-$db->SetFetchMode(ADODB_FETCH_ASSOC);
+/// list all supported drivers - unsupported must be installed manually ;-)
+$supported = array (
+ 'mysqli_adodb',
+ 'mysql_adodb',
+ 'postgres7_adodb',
+ 'mssql_n_adodb',
+ 'mssql_adodb',
+ 'odbc_mssql_adodb',
+ 'oci8po_adodb'
+);
+$databases = array ();
+foreach($supported as $driver) {
+ $classname = $driver.'_moodle_database';
+ require_once ("$CFG->libdir/dml/$classname.php");
+ $databases[$driver] = new $classname ();
+}
/// guess the www root
if ($INSTALL['wwwroot'] == '') {
@@ -241,31 +253,32 @@
error_reporting(0);
/// check wwwroot
- if (ini_get('allow_url_fopen') && false) { /// This was not reliable
+ if (ini_get('allow_url_fopen') && false) { /// This was not reliable
if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
$errormsg .= get_string('wwwrooterror', 'install').'
';
$INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
+ fclose($fh);
}
}
- if ($fh) fclose($fh);
/// check dirroot
- if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
+ if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false) {
$errormsg .= get_string('dirrooterror', 'install').'
';
$INSTALL['dirrootform'] = $INSTALL['dirroot'];
+ fclose($fh);
}
- if ($fh) fclose($fh);
/// check dataroot
$CFG->dataroot = $INSTALL['dataroot'];
- if (make_upload_directory('sessions', false) === false ) {
+ if (make_upload_directory('sessions', false) === false) {
$errormsg .= get_string('datarooterror', 'install').'
';
}
- if ($fh) fclose($fh);
- if (!empty($errormsg)) $nextstage = DIRECTORY;
+ if (!empty($errormsg)) {
+ $nextstage = DIRECTORY;
+ }
- error_reporting(7);
+ error_reporting(38911);
}
@@ -277,87 +290,36 @@
if ($INSTALL['stage'] == DATABASE) {
- /// different format for postgres7 by socket
- if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
- $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
- $INSTALL['dbuser'] = '';
- $INSTALL['dbpass'] = '';
- $INSTALL['dbname'] = '';
+ $DB = $databases[$INSTALL['dbtype']];
- if ($INSTALL['prefix'] == '') { /// must have a prefix
- $INSTALL['prefix'] = 'mdl_';
- }
- }
+ $dbfamily = $DB->get_dbfamily();
+ $errormsg = $DB->driver_installed();
- if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
- if (!extension_loaded('mysql')) {
- $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
- $nextstage = DATABASE;
- }
- }
-
- if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
- if (!extension_loaded('mysqli')) {
- $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
- $nextstage = DATABASE;
- }
- }
-
- if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
- if (!extension_loaded('pgsql')) {
- $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
- $nextstage = DATABASE;
- }
- }
-
- if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
- if (!function_exists('mssql_connect')) {
- $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
- $nextstage = DATABASE;
- }
- }
-
- if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
- if (!function_exists('mssql_connect')) {
- $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
- $nextstage = DATABASE;
- }
- }
-
- if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
- if (!extension_loaded('odbc')) {
- $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
- $nextstage = DATABASE;
- }
- }
-
- if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
- if (!extension_loaded('oci8')) {
- $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
- $nextstage = DATABASE;
- }
+ if ($errormsg === true) {
+ $errormsg = '';
+ } else {
+ $nextstage = DATABASE;
}
- if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
+ if (empty($INSTALL['prefix']) and $dbfamily != 'mysql') { // All DBs but MySQL require prefix (reserv. words)
$errormsg = get_string('dbwrongprefix', 'install');
$nextstage = DATABASE;
}
- if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
+ if ($dbfamily == 'oracle' and strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
$errormsg = get_string('dbwrongprefix', 'install');
$nextstage = DATABASE;
}
- if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
+ if ($dbfamily == 'oracle' and !empty ($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
$errormsg = get_string('dbwronghostserver', 'install');
$nextstage = DATABASE;
}
if (empty($errormsg)) {
-
error_reporting(0); // Hide errors
- if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
+ 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
@@ -373,41 +335,14 @@
}
}
} else {
- /// We have been able to connect properly, just test the database encoding now.
- /// It must be Unicode for 1.8 installations.
- $encoding = '';
- switch ($INSTALL['dbtype']) {
- case 'mysql':
- case 'mysqli':
- /// Get MySQL character_set_database value
- $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
- if ($rs && !$rs->EOF) {
- $records = $rs->GetAssoc(true);
- $encoding = $records['character_set_database']['Value'];
- if (strtoupper($encoding) != 'UTF8') {
- /// Try to set the encoding now!
- if (! $db->Metatables()) { // We have no tables so go ahead
- $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
- $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
-
- }
- }
- /// If conversion fails, skip, let environment testing do the job
- }
- break;
- case 'postgres7':
- /// Skip, let environment testing do the job
- break;
- case 'oci8po':
- /// Skip, let environment testing do the job
- break;
- }
+// TODO: db encoding checks ??
}
}
- error_reporting(7);
+ error_reporting(38911);
- if (($dbconnected === false) and (empty($errormsg)) ) {
+/// Output db connection error
+ if ((empty($errormsg) and ($dbconnected === false)) ) {
$errormsg = get_string('dbconnectionerror', 'install');
$nextstage = DATABASE;
}
@@ -441,9 +376,11 @@
// Check if we can navigate from the environemt page (because it's ok)
if ($INSTALL['stage'] == ENVIRONMENT) {
+ $DB = $databases[$INSTALL['dbtype']];
+
error_reporting(0); // Hide errors
- $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
- error_reporting(7); // Show errors
+ $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']);
+ error_reporting(38911); // Show errors
if ($dbconnected) {
/// Execute environment check, printing results
if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
@@ -500,7 +437,7 @@
//We shouldn't reach this point
}
- error_reporting(7); // Show errors
+ error_reporting(38911); // Show errors
if ($downloadsuccess) {
$INSTALL['downloadlangpack'] = false;
@@ -523,28 +460,36 @@
if ($nextstage == SAVE) {
- $str = 'dbtype = \''.$INSTALL['dbtype']."';\r\n";
- $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
- if (!empty($INSTALL['dbname'])) {
- $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
- // support single quotes in db user/passwords
- $str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
- $str .= '$CFG->dbpass = \''.addsingleslashes($INSTALL['dbpass'])."';\r\n";
+ $database = $databases[$INSTALL['dbtype']];
+ $database->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']);
+ $dbconfig = $database->export_dbconfig();
+ $dbconfig->persistent = false;
+
+ foreach ($dbconfig as $key=>$value) {
+ $key = str_pad($key, 9);
+ if (is_bool($value)) {
+ if ($value) {
+ $str .= '$CFG->'.$key.' = true;'."\r\n";
+ } else {
+ $str .= '$CFG->'.$key.' = false;'."\r\n";
+ }
+ } else {
+ $str .= '$CFG->'.$key.' = \''.addsingleslashes($value)."';\r\n";
+ }
}
- $str .= '$CFG->dbpersist = false;'."\r\n";
- $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
$str .= "\r\n";
- $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
- $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
- $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
- $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
+ $str .= '$CFG->wwwroot = \''.addsingleslashes($INSTALL['wwwrootform'])."';\r\n";
+ $str .= '$CFG->dirroot = \''.addsingleslashes($INSTALL['dirrootform'])."';\r\n";
+ $str .= '$CFG->dataroot = \''.addsingleslashes($INSTALL['dataroot'])."';\r\n";
+ $str .= '$CFG->admin = \''.addsingleslashes($INSTALL['admindirname'])."';\r\n";
$str .= "\r\n";
$str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
@@ -577,8 +522,8 @@
' . get_string('databasesettingswillbecreated', 'install') . '
'; - echo '' . get_string('databasesettingswillbecreated', 'install') . '
'; - echo '"; - echo ''; - echo get_string('moodledocslink', 'install') . '
'; - echo '"; - echo ''; - echo get_string('moodledocslink', 'install') . '
'; - echo '"; - echo ''; - echo get_string('moodledocslink', 'install') . '
'; - echo '"; - echo ''; - echo get_string('moodledocslink', 'install') . '
'; - echo '' . get_string('databasesettingswillbecreated', 'install') . '
'; + echo '' . $substagetext[$nextstage] . '
'; @@ -709,13 +614,13 @@ echo "\n"; - print_r(s($str)); + p($INSTALL['config']); echo "\n"; echo "