show_errors(); if ( defined('DB_CHARSET') ) $this->charset = DB_CHARSET; if ( defined('DB_COLLATE') ) $this->collate = DB_COLLATE; $this->dbh = @mysqli_connect($dbhost, $dbuser, $dbpassword); if (!$this->dbh) { $this->bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/"

Error establishing a database connection

This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at %s. This could mean your host's database server is down.

If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

"/*/WP_I18N_DB_CONN_ERROR*/, $dbhost)); return; } $this->ready = true; if ( $this->has_cap( 'collation' ) ) { if ( !empty($this->charset) ) { if ( function_exists('mysqli_set_charset') ) { mysqli_set_charset($this->dbh, $this->charset); $this->real_escape = true; } else { $collation_query = "SET NAMES '{$this->charset}'"; if ( !empty($this->collate) ) $collation_query .= " COLLATE '{$this->collate}'"; $this->query($collation_query); } } } $this->select($dbname); } /** * Selects a database using the current database connection. * * The database name will be changed based on the current database * connection. On failure, the execution will bail and display an DB error. * * @since 0.71 * * @param string $db MySQL database name * @return null Always null. */ function select($db) { if (!@mysqli_select_db($this->dbh, $db)) { $this->ready = false; $this->bail(sprintf(/*WP_I18N_DB_SELECT_DB*/'

Can’t select database

We were able to connect to the database server (which means your username and password is okay) but not able to select the %1$s database.

If you don\'t know how to setup a database you should contact your host. If all else fails you may find help at the WordPress Support Forums.

'/*/WP_I18N_DB_SELECT_DB*/, $db, DB_USER)); return; } } function _real_escape($string) { if ( $this->dbh && $this->real_escape ) return mysqli_real_escape_string( $this->dbh, $string ); else return addslashes( $string ); } /** * Print SQL/DB error. * * @since 0.71 * @global array $EZSQL_ERROR Stores error information of query and error string * * @param string $str The error to display * @return bool False if the showing of errors is disabled. */ function print_error($str = '') { global $EZSQL_ERROR; if (!$str) $str = mysqli_error($this->dbh); $EZSQL_ERROR[] = array ('query' => $this->last_query, 'error_str' => $str); if ( $this->suppress_errors ) return false; if ( $caller = $this->get_caller() ) $error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR_FULL*/'WordPress database error %1$s for query %2$s made by %3$s'/*/WP_I18N_DB_QUERY_ERROR_FULL*/, $str, $this->last_query, $caller); else $error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR*/'WordPress database error %1$s for query %2$s'/*/WP_I18N_DB_QUERY_ERROR*/, $str, $this->last_query); $log_error = true; if ( ! function_exists('error_log') ) $log_error = false; $log_file = @ini_get('error_log'); if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) ) $log_error = false; if ( $log_error ) @error_log($error_str, 0); // Is error output turned on or not.. if ( !$this->show_errors ) return false; $str = htmlspecialchars($str, ENT_QUOTES); $query = htmlspecialchars($this->last_query, ENT_QUOTES); // If there is an error then take note of it print "

WordPress database error: [$str]
$query

"; } /** * Perform a MySQL database query, using current database connection. * * More information can be found on the codex page. * * @since 0.71 * * @param string $query * @return int|false Number of rows affected/selected or false on error */ function query($query) { if ( ! $this->ready ) return false; // filter the query, if filters are available // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method if ( function_exists('apply_filters') ) $query = apply_filters('query', $query); // initialise return $return_val = 0; $this->flush(); // Log how the function was called $this->func_call = "\$db->query(\"$query\")"; // Keep track of the last query for debug.. $this->last_query = $query; // Perform the query via std mysqli_query function.. if ( defined('SAVEQUERIES') && SAVEQUERIES ) $this->timer_start(); $this->result = @mysqli_query($this->dbh, $query); ++$this->num_queries; if ( defined('SAVEQUERIES') && SAVEQUERIES ) $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); // If there is an error then take note of it.. if ( $this->last_error = mysqli_error($this->dbh) ) { $this->print_error(); return false; } if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) { $this->rows_affected = mysqli_affected_rows($this->dbh); // Take note of the insert_id if ( preg_match("/^\\s*(insert|replace) /i",$query) ) { $this->insert_id = mysqli_insert_id($this->dbh); } // Return number of rows affected $return_val = $this->rows_affected; } else { $i = 0; while ($i < @mysqli_num_fields($this->result)) { $this->col_info[$i] = @mysqli_fetch_field($this->result); $i++; } $num_rows = 0; while ( $row = @mysqli_fetch_object($this->result) ) { $this->last_result[$num_rows] = $row; $num_rows++; } @mysqli_free_result($this->result); // Log number of rows the query returned $this->num_rows = $num_rows; // Return number of rows selected $return_val = $this->num_rows; } return $return_val; } /** * The database version number * @param false|string|resource $dbh_or_table (not implemented) Which database to test. False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource. * @return false|string false on failure, version number on success */ function db_version() { return preg_replace('/[^0-9.].*/', '', mysqli_get_server_info( $this->dbh )); } } // Load the database $wpdb = new wpdbi(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);