diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 61a5c1bca2..f3168262aa 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -1338,7 +1338,7 @@ class Database { } } return false; - } + } /* DEPRECATED METHODS diff --git a/main/install/index.php b/main/install/index.php index 9653ecc2da..413133df66 100644 --- a/main/install/index.php +++ b/main/install/index.php @@ -742,11 +742,12 @@ if ($_POST['step2']) { $perm_file = api_get_permissions_for_new_files(); if (empty($my_old_version)) { $my_old_version = '1.8.6.2'; } //we guess + $_configuration['main_database'] = $dbNameForm; //$urlAppendPath = get_config_param('urlAppend'); - error_log('Starting migration process from '.$my_old_version.' ('.time().')', 0); + error_log('Starting migration process from '.$my_old_version.' ('.time().')', 0); - if ($userPasswordCrypted == '1') { + if ($userPasswordCrypted == '1') { $userPasswordCrypted = 'md5'; } elseif ($userPasswordCrypted == '0') { $userPasswordCrypted = 'none'; @@ -822,7 +823,8 @@ if ($_POST['step2']) { default: break; } - } else { + } else { + set_file_folder_permissions(); database_server_connect(); diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 26c4c9d662..2d6075e338 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -597,12 +597,19 @@ function database_server_connect() { @Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5) } +/** + * Database exists for the MYSQL user + * @param type $database_name + * @return boolean + */ function database_exists($database_name) { + $select_database = Database::select_db($database_name); + $show_database = false; $result = @Database::query("SHOW DATABASES LIKE '".Database::escape_string($database_name)."' "); if (Database::num_rows($result)) { - return true; - } - return false; + $show_database = true; + } + return $select_database || $show_database; } /** @@ -618,7 +625,7 @@ function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbFor $dbConnect = -1; //Checking user credentials if (@Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)) !== false) { - $check_user_can_create_databases = true; + //$check_user_can_create_databases = true; //Checking if single database exist /*if ($singleDbForm) { @@ -653,7 +660,7 @@ function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbFor } else { $dbConnect = -1; } - return $dbConnect; //return "1"if no problems, "0" if, in case we can't create a new DB and "-1" if there is no connection. + return $dbConnect; //return 1, if no problems, "0" if, in case we can't create a new DB and "-1" if there is no connection. } /** @@ -1731,9 +1738,35 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo '.get_lang('ADatabaseWithTheSameNameAlreadyExists').''; + } else { + if (!$dbConnect) { + $database_exists_text = '
'; + } else { + //Try to create the database + $user_can_create_databases = false; + $multipleDbCheck = @Database::query("CREATE DATABASE test_chamilo_connection"); + if ($multipleDbCheck !== false) { + $multipleDbCheck = @Database::query("DROP DATABASE IF EXISTS test_chamilo_connection"); + $user_can_create_databases = true; + } + + if ($user_can_create_databases) { + $database_exists_text = ''; + } else { + $dbConnect = 0; + $database_exists_text = ''; + } + } + } + if ($dbConnect == 1): ?>