Example #1
0
// Use Quizdb later once we have created the database
require_once $app_dir . "/includes/Database.php";
$db = new Database($dbsettings);
// Connected
if ($db->getStatus() == 1) {
    // status = 1 - means that we have connected to database and the database exists (use db)
    // we are not asking user to confirm that they are installing into these database
    // in many cases the database will need to be created outside of the install script so don't
    // want to impose too many "are you sure?" questions
    // we will still not overwrite as we check tables don't exist before creating
    $action_required = 'tables';
} elseif ($db->getStatus() == -2) {
    // We can only create db if we are on mysql (in this version)
    if ($dbsettings['dbtype'] == 'mysql') {
        // Try creating database
        if (!$db->createDb($dbsettings['database'])) {
            // unable to create database - most likely permissions - hosted accounts may need to create
            // the database using the hosting cpanel etc.
            displayDbError("Unable to create new database " . $dbsettings['database'] . " <br />\nThis is normally due to insufficient permissions. If using a hosting account on a shared server you may need to use cpanel or ask your hosting provider for how to create a database<br />\nPlease read the install documentation for more details and then create the database manually before reloading this page.\n");
            exit(0);
        } else {
            $status_msg .= "\nNew database created " . $dbsettings['database'] . "<br />\n\n";
            // now connect to the new database
            if (!$db->connectDb($dbsettings['database'])) {
                // shouldn't get this as if we have permission to create the database we should be able to connect to it. Perhaps we have lost our network connection
                $error_msg = $db->getError();
                displayDbError("Unable to connect to the new database " . $dbsettings['database'] . " <br />\nError {$error_msg}.\n");
                exit(0);
            } else {
                $status_msg .= "\nConnected to the new database <br />\n\n";
                $action_required = 'tables';