本文整理汇总了PHP中wpdb::check_connection方法的典型用法代码示例。如果您正苦于以下问题:PHP wpdb::check_connection方法的具体用法?PHP wpdb::check_connection怎么用?PHP wpdb::check_connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wpdb
的用法示例。
在下文中一共展示了wpdb::check_connection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: data_collector_page
/**
* Display Settings page of the module.
*/
public function data_collector_page()
{
$dc_hostname = get_option('ltg_q_dc_hostname', '');
$dc_port = get_option('ltg_q_dc_port', '');
$dc_database = get_option('ltg_q_dc_database', '');
$dc_login = get_option('ltg_q_dc_login', '');
$dc_password = get_option('ltg_q_dc_password', '');
// Connect to the data collector server
$dc_con = new wpdb($dc_login, $dc_password, $dc_database, $dc_hostname . ':' . $dc_port);
// Check connection to the server
if (!$dc_con->check_connection(false)) {
echo '<div class="wrap">
<h2>Data Collector</h2>
<p>The connection to the database cannot be established. Please update the
<a href="admin.php?page=ltg-questionnaires">settings of the Data Collector</a>.</p>
</div>';
exit;
}
include_once dirname(__FILE__) . '/partials/ltg_questionnaires-data-collector.php';
}
示例2: answerfieldtypes
* THIS FILE IS ONLY FOR DEVELOPMENT PURPOSES.
* IT POSES A LOT OF SECURITY RISKS (e.g. SQL INJECTION)
* DO NOT USE ON PRODUCTION ENVIRONMENTS!
*/
// @TODO: Use WP functions to detect if the visitor is logged in or not.
// Bootstrap Wordpress
require_once '../../../wp-load.php';
$dc_hostname = get_option('ltg_q_dc_hostname', '');
$dc_port = get_option('ltg_q_dc_port', '');
$dc_database = get_option('ltg_q_dc_database', '');
$dc_login = get_option('ltg_q_dc_login', '');
$dc_password = get_option('ltg_q_dc_password', '');
// Connect to the data collector server
$dc_con = new wpdb($dc_login, $dc_password, $dc_database, $dc_hostname . ':' . $dc_port);
// Check connection to the server
if (!$dc_con->check_connection(false)) {
$return = array('error' => 'Database connection problems.');
echo json_encode($return);
exit;
}
$resource = $_GET['resource'];
if (function_exists($_GET['resource'])) {
$op = $_GET['op'] ? $_GET['op'] : 'r';
$resource();
}
function answerfieldtypes()
{
global $dc_con, $op;
switch ($op) {
case 'r':
$order = $_GET['order'] ? $_GET['order'] : 'answerfieldtype_id';
示例3: restoreWpdbConnection
private function restoreWpdbConnection()
{
if (!class_exists('wpdb')) {
return;
}
/** @var \wpdb $wpdb */
global $wpdb;
if (empty($wpdb)) {
$wpdb = new \wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
} else {
$wpdb->db_connect();
$wpdb->check_connection();
}
/**
* To avoid `mysqli_free_result` errors during the `wpdb::flush()` method set the result to `null`.
* See `wp-db.php` file line 1425.
*/
$reflection = new \ReflectionClass($wpdb);
$resultProperty = $reflection->getProperty('result');
$resultProperty->setAccessible(true);
$resultProperty->setValue($wpdb, null);
$resultProperty->setAccessible(false);
}