wpdb::close() WordPress Method

The wpdb::close() method is used to close a database connection. This is useful for ensuring that all database connections are properly closed when your script finishes execution.

wpdb::close() #

Closes the current database connection.


Return

(bool) True if the connection was successfully closed, false if it wasn't, or if the connection doesn't exist.


Top ↑

Source

File: wp-includes/wp-db.php

	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;
	}

Top ↑

Changelog

Changelog
VersionDescription
4.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.