Example #1
0
if (!isset($_POST['dbuser'])) {
    $_POST['dbuser'] = '';
}
if (!isset($_POST['dbpass'])) {
    $_POST['dbpass'] = '';
}
if (!isset($_POST['dbname'])) {
    $_POST['dbname'] = '';
}
if (!isset($_POST['tblpfx'])) {
    $_POST['tblpfx'] = 'wt_';
}
define('WT_TBLPREFIX', $_POST['tblpfx']);
$db_version_ok = false;
try {
    Database::createInstance($_POST['dbhost'], $_POST['dbport'], '', $_POST['dbuser'], $_POST['dbpass']);
    Database::exec("SET NAMES 'utf8'");
    $row = Database::prepare("SHOW VARIABLES LIKE 'VERSION'")->fetchOneRow();
    if (version_compare($row->value, WT_REQUIRED_MYSQL_VERSION, '<')) {
        echo '<p class="bad">', I18N::translate('This database is only running MySQL version %s.  You cannot install webtrees here.', $row->value), '</p>';
    } else {
        $db_version_ok = true;
    }
} catch (PDOException $ex) {
    Database::disconnect();
    if ($_POST['dbuser']) {
        // If we’ve supplied a login, then show the error
        echo '<p class="bad">', I18N::translate('Unable to connect using these settings.  Your server gave the following error.'), '</p>', '<pre>', $ex->getMessage(), '</pre>', '<p class="bad">', I18N::translate('Check the settings and try again.'), '</p>';
    }
}
if (empty($_POST['dbuser']) || !Database::isConnected() || !$db_version_ok) {
Example #2
0
} else {
    // No config file. Set one up.
    header('Location: ' . WT_BASE_URL . 'setup.php');
    exit;
}
// What is the remote client's IP address
if (Filter::server('HTTP_CLIENT_IP') !== null) {
    define('WT_CLIENT_IP', Filter::server('HTTP_CLIENT_IP'));
} elseif (Filter::server('HTTP_X_FORWARDED_FOR') !== null) {
    define('WT_CLIENT_IP', Filter::server('HTTP_X_FORWARDED_FOR'));
} else {
    define('WT_CLIENT_IP', Filter::server('REMOTE_ADDR', WT_REGEX_IPV4, '127.0.0.1'));
}
// Connect to the database
try {
    Database::createInstance($dbconfig['dbhost'], $dbconfig['dbport'], $dbconfig['dbname'], $dbconfig['dbuser'], $dbconfig['dbpass']);
    define('WT_TBLPREFIX', $dbconfig['tblpfx']);
    unset($dbconfig);
    // Some of the FAMILY JOIN HUSBAND JOIN WIFE queries can excede the MAX_JOIN_SIZE setting
    Database::exec("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci', SQL_BIG_SELECTS=1");
    // Update the database schema
    Database::updateSchema('\\Fisharebest\\Webtrees\\Schema', 'WT_SCHEMA_VERSION', WT_SCHEMA_VERSION);
} catch (PDOException $ex) {
    FlashMessages::addMessage($ex->getMessage(), 'danger');
    header('Location: ' . WT_BASE_URL . 'site-unavailable.php');
    throw $ex;
}
// The config.ini.php file must always be in a fixed location.
// Other user files can be stored elsewhere...
define('WT_DATA_DIR', realpath(Site::getPreference('INDEX_DIRECTORY') ? Site::getPreference('INDEX_DIRECTORY') : 'data') . DIRECTORY_SEPARATOR);
// If we have a preferred URL (e.g. www.example.com instead of www.isp.com/~example), then redirect to it.