wpdb::log_query() WordPress Method

The wpdb::log_query() method is used to log database queries for debugging purposes. This is useful when you want to see how WordPress is interacting with the database. The query is written to the WordPress debug log.

wpdb::log_query( string $query, float $query_time, string $query_callstack, float $query_start, array $query_data ) #

Logs query data.


Parameters

$query

(string)(Required)The query's SQL.

$query_time

(float)(Required)Total time spent on the query, in seconds.

$query_callstack

(string)(Required)Comma-separated list of the calling functions.

$query_start

(float)(Required)Unix timestamp of the time at the start of the query.

$query_data

(array)(Required)Custom query data.


Top ↑

Source

File: wp-includes/wp-db.php

	public function log_query( $query, $query_time, $query_callstack, $query_start, $query_data ) {
		/**
		 * Filters the custom data to log alongside a query.
		 *
		 * Caution should be used when modifying any of this data, it is recommended that any additional
		 * information you need to store about a query be added as a new associative array element.
		 *
		 * @since 5.3.0
		 *
		 * @param array  $query_data      Custom query data.
		 * @param string $query           The query's SQL.
		 * @param float  $query_time      Total time spent on the query, in seconds.
		 * @param string $query_callstack Comma-separated list of the calling functions.
		 * @param float  $query_start     Unix timestamp of the time at the start of the query.
		 */
		$query_data = apply_filters( 'log_query_custom_data', $query_data, $query, $query_time, $query_callstack, $query_start );

		$this->queries[] = array(
			$query,
			$query_time,
			$query_callstack,
			$query_start,
			$query_data,
		);
	}


Top ↑

Changelog

Changelog
VersionDescription
5.3.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.