本文整理汇总了PHP中Fisharebest\Webtrees\Database::createInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::createInstance方法的具体用法?PHP Database::createInstance怎么用?PHP Database::createInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fisharebest\Webtrees\Database
的用法示例。
在下文中一共展示了Database::createInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
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) {
示例2: header
} 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.