\MatthiasWeb\RealMediaLibrary\comp\complexqueryComplexQuery

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

Examples

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

** File not found : $rows **

Summary

Methods
Properties
Constants
getPluginConstantPrefix()
__construct()
getResult()
singleQuery()
procedure()
fallback()
install()
hasProcedure()
isSingleQueriableWithUserDefinedVars()
isProcedurable()
_isProcedurable()
isMysqli()
getWpdb()
getDbh()
getCache()
No public properties found
CACHE_OPTION_NAME
getProcedureResults()
No protected properties found
N/A
No private methods found
$wpdb
$isProcedurable
$cache
N/A

Constants

CACHE_OPTION_NAME

CACHE_OPTION_NAME ='mw_complex_query'

Properties

$wpdb

$wpdb :

Type

$isProcedurable

$isProcedurable :

Type

$cache

$cache :

Type

Methods

getPluginConstantPrefix()

getPluginConstantPrefix(): string

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

Returns

string

__construct()

__construct(\wpdb  $wpdb)

C'tor.

Parameters

\wpdb $wpdb

getResult()

getResult(): mixed

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

Returns

mixed

singleQuery()

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.

Returns

mixed

procedure()

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.

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

Returns

mixed

fallback()

fallback(): mixed

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

Returns

mixed

install()

install(callable  $callable)

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

Parameters

callable $callable

The callable to install the procedure for example

hasProcedure()

hasProcedure(string  $procedure): boolean

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

Parameters

string $procedure

Returns

boolean

isSingleQueriableWithUserDefinedVars()

isSingleQueriableWithUserDefinedVars(): boolean

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.

This method uses a cache (30 days).

Returns

boolean

isProcedurable()

isProcedurable(): boolean

Checks if procedures are allowed. This function uses a cache (30 days).

Returns

boolean

_isProcedurable()

_isProcedurable()

Installs a procedure and checks if it can be used.

isMysqli()

isMysqli(): boolean

Checks if the database handle is mysqli or not.

Returns

boolean

getWpdb()

getWpdb(): \wpdb

Getter.

Returns

\wpdb

getDbh()

getDbh(): string

Getter.

Returns

string

getCache()

getCache(): mixed

Get cache.

Returns

mixed

getProcedureResults()

getProcedureResults(string  $sql,boolean  $returnTrue = false): Array

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

Parameters

string $sql

The SQL string to execute

boolean $returnTrue

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

Returns

Array —

or false when an error occur