*/
public $termmeta;
- /*
- * Global and Multisite tables
- */
+ //
+ // Global and Multisite tables
+ //
/**
* WordPress User Metadata table
$dbh = $this->dbh;
if ( $this->use_mysqli ) {
- $success = @mysqli_select_db( $dbh, $db );
+ $success = mysqli_select_db( $dbh, $db );
} else {
- $success = @mysql_select_db( $db, $dbh );
+ $success = mysql_select_db( $db, $dbh );
}
if ( ! $success ) {
$this->ready = false;
* Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security.
*
* Example Prepared Statement:
- * $wild = '%';
- * $find = 'only 43% of planets';
- * $like = $wild . $wpdb->esc_like( $find ) . $wild;
- * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE %s", $like );
+ *
+ * $wild = '%';
+ * $find = 'only 43% of planets';
+ * $like = $wild . $wpdb->esc_like( $find ) . $wild;
+ * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like );
*
* Example Escape Chain:
- * $sql = esc_sql( $wpdb->esc_like( $input ) );
+ *
+ * $sql = esc_sql( $wpdb->esc_like( $input ) );
*
* @since 4.0.0
* @access public
}
}
- if ( WP_DEBUG ) {
- mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
- } else {
- @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
- }
+ mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
if ( $this->dbh->connect_errno ) {
$this->dbh = null;
}
}
} else {
- if ( WP_DEBUG ) {
- $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
- } else {
- $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
- }
+ $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
}
if ( ! $this->dbh && $allow_bail ) {
*/
public function check_connection( $allow_bail = true ) {
if ( $this->use_mysqli ) {
- if ( @mysqli_ping( $this->dbh ) ) {
+ if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) {
return true;
}
} else {
- if ( @mysql_ping( $this->dbh ) ) {
+ if ( ! empty( $this->dbh ) && mysql_ping( $this->dbh ) ) {
return true;
}
}
} else {
$num_rows = 0;
if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
- while ( $row = @mysqli_fetch_object( $this->result ) ) {
+ while ( $row = mysqli_fetch_object( $this->result ) ) {
$this->last_result[$num_rows] = $row;
$num_rows++;
}
} elseif ( is_resource( $this->result ) ) {
- while ( $row = @mysql_fetch_object( $this->result ) ) {
+ while ( $row = mysql_fetch_object( $this->result ) ) {
$this->last_result[$num_rows] = $row;
$num_rows++;
}
$this->timer_start();
}
- if ( $this->use_mysqli ) {
- $this->result = @mysqli_query( $this->dbh, $query );
- } else {
- $this->result = @mysql_query( $query, $this->dbh );
+ if ( ! empty( $this->dbh ) && $this->use_mysqli ) {
+ $this->result = mysqli_query( $this->dbh, $query );
+ } elseif ( ! empty( $this->dbh ) ) {
+ $this->result = mysql_query( $query, $this->dbh );
}
$this->num_queries++;
return;
if ( $this->use_mysqli ) {
- $num_fields = @mysqli_num_fields( $this->result );
+ $num_fields = mysqli_num_fields( $this->result );
for ( $i = 0; $i < $num_fields; $i++ ) {
- $this->col_info[ $i ] = @mysqli_fetch_field( $this->result );
+ $this->col_info[ $i ] = mysqli_fetch_field( $this->result );
}
} else {
- $num_fields = @mysql_num_fields( $this->result );
+ $num_fields = mysql_num_fields( $this->result );
for ( $i = 0; $i < $num_fields; $i++ ) {
- $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i );
+ $this->col_info[ $i ] = mysql_fetch_field( $this->result, $i );
}
}
}
wp_die($message);
}
+
+ /**
+ * Closes the current database connection.
+ *
+ * @since 4.5.0
+ * @access public
+ *
+ * @return bool True if the connection was successfully closed, false if it wasn't,
+ * or the connection doesn't exist.
+ */
+ public function close() {
+ if ( ! $this->dbh ) {
+ return false;
+ }
+
+ if ( $this->use_mysqli ) {
+ $closed = mysqli_close( $this->dbh );
+ } else {
+ $closed = mysql_close( $this->dbh );
+ }
+
+ if ( $closed ) {
+ $this->dbh = null;
+ $this->ready = false;
+ $this->has_connected = false;
+ }
+
+ return $closed;
+ }
+
/**
* Whether MySQL database is at least the required minimum version.
*
}
/**
- * The database version number.
+ * Retrieves the MySQL server version.
*
* @since 2.7.0
*