Documentation

ComplexQuery
in package
Uses UtilsProvider

AbstractYes

Define your complex SQL query. When implementing your complex query do not use global $wpdb; in your methods. Use ::getWpdb() instead.

A complex query can be splitted into three parts:

  • 1. Single Query: The query can be processed through one single SQL query with user defined variables
  • 2. Procedure: The procedure can write for example to an temporary table and reads again from this one
  • 3. Fallback: The fallback can throw an error or do the query through PHP functions
Tags
example

$rows = new MyComplexQuery($wpdb)->getResults();

Table of Contents

Constants

CACHE_OPTION_NAME  = 'mw_complex_query'

Properties

$cache  : mixed
$isProcedurable  : mixed
$wpdb  : mixed

Methods

__construct()  : mixed
C'tor.
_isProcedurable()  : mixed
Installs a procedure and checks if it can be used.
fallback()  : mixed
This function is called when a single query is not possible and procedures are not allowed.
getCache()  : mixed
Get cache.
getDbh()  : string
Getter.
getPluginConstantPrefix()  : string
Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
getResult()  : mixed
Get the result from the three different result types: singleQuery, procedure or fallback.
getWpdb()  : wpdb
Getter.
hasProcedure()  : bool
Checks if a given procedure is available for the current user.
install()  : mixed
Start an installer. Use this function in your procedure() method.
isMysqli()  : bool
Checks if the database handle is mysqli or not.
isProcedurable()  : bool
Checks if procedures are allowed. This function uses a cache (30 days).
isSingleQueriableWithUserDefinedVars()  : bool
Checks if a single query is allowed to use @vars. For example MariaDB does not resolve @vars in a single query when they are not declared before.
procedure()  : mixed
This function is called when procedures (stored functions and procedures) are available. It is also necessary that mysqli is in use. mysql_connect does not support store_results() method. This method should return your expected result. You should work with this::hasProcedure() to install your procedure if not exists.
singleQuery()  : mixed
This function is called when user defined variables are support. This method should return your expected result. It works with both mysqli_connect and mysql_connect.
getProcedureResults()  : array<string|int, mixed>
Call a "CALL proc" SQL and parse the results.

Constants

CACHE_OPTION_NAME

public mixed CACHE_OPTION_NAME = 'mw_complex_query'

Properties

Methods

__construct()

C'tor.

public __construct(wpdb $wpdb) : mixed
Parameters
$wpdb : wpdb

_isProcedurable()

Installs a procedure and checks if it can be used.

public final _isProcedurable() : mixed

fallback()

This function is called when a single query is not possible and procedures are not allowed.

public abstract fallback() : mixed

getDbh()

Getter.

public getDbh() : string
Return values
string

getPluginConstantPrefix()

Get the prefix of this plugin so composer packages can dynamically build other constant values on it.

public getPluginConstantPrefix() : string
Tags
codeCoverageIgnore

It only returns a string with the constant prefix

Return values
string

getResult()

Get the result from the three different result types: singleQuery, procedure or fallback.

public getResult() : mixed

getWpdb()

Getter.

public getWpdb() : wpdb
Return values
wpdb

hasProcedure()

Checks if a given procedure is available for the current user.

public hasProcedure(string $procedure) : bool
Parameters
$procedure : string
Return values
bool

install()

Start an installer. Use this function in your procedure() method.

public final install(callable $callable) : mixed
Parameters
$callable : callable

The callable to install the procedure for example

isMysqli()

Checks if the database handle is mysqli or not.

public isMysqli() : bool
Return values
bool

isSingleQueriableWithUserDefinedVars()

Checks if a single query is allowed to use @vars. For example MariaDB does not resolve @vars in a single query when they are not declared before.

public isSingleQueriableWithUserDefinedVars() : bool

This method uses a cache (30 days).

Return values
bool

procedure()

This function is called when procedures (stored functions and procedures) are available. It is also necessary that mysqli is in use. mysql_connect does not support store_results() method. This method should return your expected result. You should work with this::hasProcedure() to install your procedure if not exists.

public abstract procedure() : mixed

A procedure can for example write into a temporary table and reads from it again.

singleQuery()

This function is called when user defined variables are support. This method should return your expected result. It works with both mysqli_connect and mysql_connect.

public abstract singleQuery() : mixed

getProcedureResults()

Call a "CALL proc" SQL and parse the results.

protected final getProcedureResults(string $sql[, bool $returnTrue = false ]) : array<string|int, mixed>
Parameters
$sql : string

The SQL string to execute

$returnTrue : bool = false

When the CALL is successfully and has no results then return true instead of an empty array

Return values
array<string|int, mixed>

or false when an error occur


        
On this page

Search results