當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Database::isConnected方法代碼示例

本文整理匯總了PHP中Fisharebest\Webtrees\Database::isConnected方法的典型用法代碼示例。如果您正苦於以下問題:PHP Database::isConnected方法的具體用法?PHP Database::isConnected怎麽用?PHP Database::isConnected使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Fisharebest\Webtrees\Database的用法示例。


在下文中一共展示了Database::isConnected方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: catch

    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) {
    echo '<h2>', I18N::translate('Connection to database server'), '</h2>', '<p>', I18N::translate('webtrees needs a MySQL database, version %s or later.', WT_REQUIRED_MYSQL_VERSION), '</p>', '<p>', I18N::translate('Your server’s administrator will provide you with the connection details.'), '</p>', '<fieldset><legend>', I18N::translate('Database connection'), '</legend>', '<table border="0"><tr><td>', I18N::translate('Server name'), '</td><td>', '<input type="text" name="dbhost" value="', Filter::escapeHtml($_POST['dbhost']), '" dir="ltr"></td><td>', I18N::translate('Most sites are configured to use localhost.  This means that your database runs on the same computer as your web server.'), '</td></tr><tr><td>', I18N::translate('Port number'), '</td><td>', '<input type="text" name="dbport" value="', Filter::escapeHtml($_POST['dbport']), '"></td><td>', I18N::translate('Most sites are configured to use the default value of 3306.'), '</td></tr><tr><td>', I18N::translate('Database user account'), '</td><td>', '<input type="text" name="dbuser" value="', Filter::escapeHtml($_POST['dbuser']), '" autofocus></td><td>', I18N::translate('This is case sensitive.'), '</td></tr><tr><td>', I18N::translate('Database password'), '</td><td>', '<input type="password" name="dbpass" value="', Filter::escapeHtml($_POST['dbpass']), '"></td><td>', I18N::translate('This is case sensitive.'), '</td></tr><tr><td>', '</td></tr></table>', '</fieldset>', '<br><hr><input type="submit" id="btncontinue" value="', I18N::translate('continue'), '">', '</form>', '</body></html>';
    return;
} else {
    // Copy these values through to the next step
    echo '<input type="hidden" name="dbhost" value="', Filter::escapeHtml($_POST['dbhost']), '">';
    echo '<input type="hidden" name="dbport" value="', Filter::escapeHtml($_POST['dbport']), '">';
    echo '<input type="hidden" name="dbuser" value="', Filter::escapeHtml($_POST['dbuser']), '">';
    echo '<input type="hidden" name="dbpass" value="', Filter::escapeHtml($_POST['dbpass']), '">';
}
////////////////////////////////////////////////////////////////////////////////
// Step four - Database connection.
////////////////////////////////////////////////////////////////////////////////
// The character ` is not valid in database or table names (even if escaped).
// By removing it, we can ensure that our SQL statements are quoted correctly.
//
開發者ID:tunandras,項目名稱:webtrees,代碼行數:31,代碼來源:setup.php


注:本文中的Fisharebest\Webtrees\Database::isConnected方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。