Builder::exists()

Execute an EXISTS() call using the created query as subquery of the EXISTS function.


Return

(bool) True If the query has at least 1 result available, false otherwise.


Top ↑

Source

File: src/Events/Custom_Tables/V1/Models/Builder.php

	public function exists() {
		if ( $this->invalid ) {
			return false;
		}

		global $wpdb;

		$this->operation = 'SELECT *';

		// If the query is invalid, don't return a single result.
		if ( $this->invalid ) {
			return false;
		}

		$subquery = $this->get_sql();

		$SQL             = "SELECT * FROM `{$wpdb->prefix}{$this->model->table_name()}` WHERE EXISTS ($subquery)";
		$this->queries[] = $SQL;

		if ( $this->execute_queries ) {
			return (bool) $wpdb->get_var( $SQL );
		}

		return false;
	}

Top ↑

Changelog

Changelog
Version Description
6.0.0 Introduced.