vBulletin 5.6.5 API

vB_Database_MySQLi extends vB_Database
in package

Class to interface with a MySQL 4.1 database

This class also handles data replication between a master and slave(s) servers

Tags
version

$Revision: 105631 $

date

$Date: 2020-07-20 16:05:58 -0700 (Mon, 20 Jul 2020) $

Table of Contents

DBARRAY_ASSOC  = 1
DBARRAY_BOTH  = 0
The type of result set to return from the database for a specific row.
DBARRAY_NUM  = 2
$appname  : string
Full name of the system
$appshortname  : string
Short name of the system
$connection_master  : string
Link variable. The connection to the master/write server.
$connection_recent  : string
Link variable. The connection last used.
$connection_slave  : string
Link variable. The connection to the slave/read server(s).
$database  : string
Database name
$doExplain  : bool
Whether or not to log the queries to generate query "explain" output
$errno  : int
The error number of the most recent database error message
$error  : string
The text of the most recent database error message
$fetchtypes  : array<string|int, mixed>
Array of constants for use in fetch_array
$functions  : array<string|int, mixed>
Array of function names, mapping a simple name to the RDBMS specific function name
$locked  : bool
Track lock status of tables. True if a table lock has been issued
$maxpacket  : int
SQL Query String
$multiserver  : mixed
$querycount  : int
Number of queries executed
$reporterror  : bool
Whether or not to show and halt on database errors
$shutdownqueries  : array<string|int, mixed>
Array of queries to be executed when the script shuts down
$sql  : string
The contents of the most recent SQL query string.
$dbconfig  : array<string|int, mixed>
Reference to the sensitive database configuration array from class vB. Contains information required to connect to the database.
$explain  : array<string|int, mixed>
Array of information on each query, used for the "explain" output
$inTransaction  : mixed
$phpTime  : array<string|int, mixed>
Time information for queries, used by the "explain" output
$reconnectAttempts  : mixed
$retries  : mixed
$sqlTime  : mixed
$startTime  : mixed
__construct()  : mixed
vB_Database constructor.
__serialize()  : mixed
__sleep()  : mixed
__unserialize()  : mixed
__wakeup()  : mixed
affected_rows()  : int
Retuns the number of rows affected by the most recent insert/replace/update query
beginTransaction()  : mixed
Standard transaction handler.
catch_db_error()  : mixed
Feeds database connection errors into the halt() method of the vB_Database class.
clean_identifier()  : string
Cleans a string to make it safe to be used in an SQL query as a table name or column/field name
client_encoding()  : string
Returns the name of the character set
close()  : int
Closes the connection to the database server
commitTransaction()  : mixed
Standard transaction handler.
connect()  : none
Connects to the specified database server(s)
connect_using_dbconfig()  : mixed
create_database_using_dbconfig()  : mixed
data_seek()  : bool
Moves the internal result pointer within a query result set
errno()  : int
Returns the numerical value of the error message from previous database operation
error()  : string
Returns the text of the error message from previous database operation
escape_string()  : string
Escapes a string to make it safe to be inserted into an SQL query
escape_string_like()  : string
Escapes a string using the appropriate escape character for the RDBMS for use in LIKE conditions
fetch_array()  : array<string|int, mixed>
Fetches a row from a query result and returns the values from that row as an array
fetch_field()  : array<string|int, mixed>
Fetches a row information from a query result and returns the values from that row as an array
fetch_my_query_status()  : mixed
fetch_row()  : array<string|int, mixed>
Fetches a row from a query result and returns the values from that row as an array with numeric keys
fetchInTransaction()  : mixed
tell whether we are currently in a transaction
field_name()  : string
Returns the name of a field from within a query result set
force_sql_mode()  : mixed
Forces the sql_mode varaible to a specific mode. Certain modes may be incompatible with vBulletin. Applies to MySQL 4.1+.
found_rows()  : int
Executes a FOUND_ROWS query to get the results of SQL_CALC_FOUND_ROWS
free_result()  : bool
Frees all memory associated with the specified query result
getCriticalErrors()  : array<string|int, mixed>
Function to return the codes of critical errors when testing if a database is a valid vB5 database - normally database not found and table not found errors.
getExplain()  : mixed
At the end of the request, this returns the generated "explain" output for display
getInitialClientCharset()  : mixed
Returns the *default* character encoding of the client which is not necesarily the one we are using.
halt()  : int
Halts execution of the entire system and displays an error message
hasConfigCharset()  : mixed
Is there a charset explicitly set in the db config.
hide_errors()  : mixed
Switches database error display OFF
insert_id()  : int
Returns the ID of the item just inserted into an auto-increment field
insert_multiple()  : mixed
Executes an INSERT or REPLACE query with multiple values, splitting large queries into manageable chunks based on $this->maxpacket
isExplainEmpty()  : bool
Checks if explain array is empty
lock_tables()  : mixed
Lock tables
num_fields()  : int
Returns the number of fields contained within a query result set
num_rows()  : int
Returns the number of rows contained within a query result set
ping()  : mixed
Ping connection and reconnect Don't use this in a manner that could cause a loop condition
query()  : string
Executes an SQL query, using either the write connection
query_first()  : array<string|int, mixed>
Executes a data-reading SQL query, then returns an array of the data from the first row from the result set
query_first_slave()  : array<string|int, mixed>
Executes a data-reading SQL query against the slave server, then returns an array of the data from the first row from the result set
query_insert()  : mixed
Executes an INSERT INTO query, using extended inserts if possible
query_read()  : string
Executes a data-reading SQL query through the 'master' database connection we don't know if the 'read' database is up to date so be on the safe side
query_read_slave()  : string
Executes a data-reading SQL query through the 'slave' database connection
query_replace()  : mixed
Executes a REPLACE INTO query, using extended inserts if possible
query_write()  : string
Executes a data-writing SQL query through the 'master' database connection
rollbackTransaction()  : mixed
Standard transaction handler.
select_db()  : bool
Selects a database to use
select_db_using_dbconfig()  : mixed
select_db_wrapper()  : bool
Simple wrapper for select_db(), to allow argument order changes
show_errors()  : mixed
Switches database error display ON
shutdown_query()  : bool
Registers an SQL query to be executed at shutdown time. If shutdown functions are disabled, the query is run immediately.
sql_prepare()  : mixed
Takes a piece of data and prepares it to be put into an SQL query by adding quotes etc.
unlock_tables()  : mixed
Unlock tables
db_connect()  : object
Initialize database connection(s)
execute_query()  : string
Executes an SQL query through the specified connection
postLogQueryToExplain()  : mixed
Finishes logging a query for "explain" output, called after running the query
preLogQueryToExplain()  : int
Initializes logging a query for "explain" output
runExplainQuery()  : string
Helper function used by getExplain to run the EXPLAIN query for the current query
set_charset()  : mixed
getErrorData()  : mixed
reset_db_connection()  : mixed

Constants

DBARRAY_ASSOC

public mixed DBARRAY_ASSOC = 1

DBARRAY_BOTH

The type of result set to return from the database for a specific row.

public mixed DBARRAY_BOTH = ""

DBARRAY_NUM

public mixed DBARRAY_NUM = 2

Properties

$appname

Full name of the system

public string $appname = 'vBulletin'

$appshortname

Short name of the system

public string $appshortname = 'vBulletin'

$connection_master

Link variable. The connection to the master/write server.

public string $connection_master = ull

$connection_recent

Link variable. The connection last used.

public string $connection_recent = ull

$connection_slave

Link variable. The connection to the slave/read server(s).

public string $connection_slave = ull

$database

Database name

public string $database = ull

$doExplain

Whether or not to log the queries to generate query "explain" output

public bool $doExplain = alse

$errno

The error number of the most recent database error message

public int $errno = ''

$error

The text of the most recent database error message

public string $error = ''

$fetchtypes

Array of constants for use in fetch_array

public array<string|int, mixed> $fetchtypes = array(self::DBARRAY_NUM => MYSQLI_NUM, self::DBARRAY_ASSOC => MYSQLI_ASSOC, self::DBARRAY_BOTH => MYSQLI_BOTH)

$functions

Array of function names, mapping a simple name to the RDBMS specific function name

public array<string|int, mixed> $functions = array( 'connect' => 'mysqli_real_connect', 'pconnect' => 'mysqli_real_connect', // mysqli doesn't support persistent connections THANK YOU! 'select_db' => 'mysqli_select_db', 'query' => 'mysqli_query', 'query_unbuffered' => 'mysqli_unbuffered_query', 'fetch_row' => 'mysqli_fetch_row', 'fetch_array' => 'mysqli_fetch_array', 'fetch_field' => 'mysqli_fetch_field', 'free_result' => 'mysqli_free_result', 'data_seek' => 'mysqli_data_seek', 'error' => 'mysqli_error', 'errno' => 'mysqli_errno', 'affected_rows' => 'mysqli_affected_rows', 'num_rows' => 'mysqli_num_rows', 'num_fields' => 'mysqli_num_fields', 'field_name' => 'mysqli_field_tell', 'insert_id' => 'mysqli_insert_id', 'escape_string' => 'mysqli_real_escape_string', 'real_escape_string' => 'mysqli_real_escape_string', 'close' => 'mysqli_close', 'client_encoding' => 'mysqli_client_encoding', 'ping' => 'mysqli_ping', )

$locked

Track lock status of tables. True if a table lock has been issued

public bool $locked = alse

$maxpacket

SQL Query String

public int $maxpacket = 0

$multiserver

public mixed $multiserver = alse

$querycount

Number of queries executed

public int $querycount = 0

$reporterror

Whether or not to show and halt on database errors

public bool $reporterror = rue

$shutdownqueries

Array of queries to be executed when the script shuts down

public array<string|int, mixed> $shutdownqueries = array()

$sql

The contents of the most recent SQL query string.

public string $sql = ''

$dbconfig

Reference to the sensitive database configuration array from class vB. Contains information required to connect to the database.

protected array<string|int, mixed> $dbconfig

$explain

Array of information on each query, used for the "explain" output

protected array<string|int, mixed> $explain = array()

$inTransaction

protected mixed $inTransaction = alse

$phpTime

Time information for queries, used by the "explain" output

protected array<string|int, mixed> $phpTime = 0

$reconnectAttempts

protected mixed $reconnectAttempts = 1

$startTime

protected mixed $startTime = 0

Methods

__construct()

vB_Database constructor.

public __construct(mixed &$dbconfig, mixed &$config) : mixed
Parameters
$dbconfig : mixed
$config : mixed
Return values
mixed

__serialize()

public __serialize() : mixed
Return values
mixed

__sleep()

public __sleep() : mixed
Return values
mixed

__unserialize()

public __unserialize(mixed $serialized) : mixed
Parameters
$serialized : mixed
Return values
mixed

__wakeup()

public __wakeup() : mixed
Return values
mixed

affected_rows()

Retuns the number of rows affected by the most recent insert/replace/update query

public affected_rows() : int
Return values
int

beginTransaction()

Standard transaction handler.

public beginTransaction() : mixed
Return values
mixed

catch_db_error()

Feeds database connection errors into the halt() method of the vB_Database class.

public catch_db_error(mixed $errno, mixed $errstr, mixed $errfile, mixed $errline) : mixed
Parameters
$errno : mixed
$errstr : mixed
$errfile : mixed
$errline : mixed
Return values
mixed

clean_identifier()

Cleans a string to make it safe to be used in an SQL query as a table name or column/field name

public clean_identifier(mixed $identifier) : string
Parameters
$identifier : mixed
Return values
string

client_encoding()

Returns the name of the character set

public client_encoding() : string
Return values
string

close()

Closes the connection to the database server

public close() : int
Return values
int

commitTransaction()

Standard transaction handler.

public commitTransaction() : mixed
Return values
mixed

connect()

Connects to the specified database server(s)

public connect(mixed $database, mixed $w_servername, mixed $w_port, mixed $w_username, mixed $w_password[, mixed $w_usepconnect = false ][, mixed $r_servername = '' ][, mixed $r_port = 3306 ][, mixed $r_username = '' ][, mixed $r_password = '' ][, mixed $r_usepconnect = false ][, mixed $configfile = '' ][, mixed $charset = '' ]) : none
Parameters
$database : mixed
$w_servername : mixed
$w_port : mixed
$w_username : mixed
$w_password : mixed
$w_usepconnect : mixed = false
$r_servername : mixed = ''
$r_port : mixed = 3306
$r_username : mixed = ''
$r_password : mixed = ''
$r_usepconnect : mixed = false
$configfile : mixed = ''
$charset : mixed = ''
Return values
none

connect_using_dbconfig()

public connect_using_dbconfig([mixed $override_config = [] ]) : mixed
Parameters
$override_config : mixed = []
Return values
mixed

create_database_using_dbconfig()

public create_database_using_dbconfig() : mixed
Return values
mixed

data_seek()

Moves the internal result pointer within a query result set

public data_seek(mixed $queryresult, mixed $index) : bool
Parameters
$queryresult : mixed
$index : mixed
Return values
bool

errno()

Returns the numerical value of the error message from previous database operation

public errno() : int
Return values
int

error()

Returns the text of the error message from previous database operation

public error() : string
Return values
string

escape_string()

Escapes a string to make it safe to be inserted into an SQL query

public escape_string(mixed $string) : string
Parameters
$string : mixed
Return values
string

escape_string_like()

Escapes a string using the appropriate escape character for the RDBMS for use in LIKE conditions

public escape_string_like(mixed $string) : string
Parameters
$string : mixed
Return values
string

fetch_array()

Fetches a row from a query result and returns the values from that row as an array

public fetch_array(mixed $queryresult[, mixed $type = self::DBARRAY_ASSOC ]) : array<string|int, mixed>

The value of $type defines whether the array will have numeric or associative keys, or both

Parameters
$queryresult : mixed
$type : mixed = self::DBARRAY_ASSOC
Return values
array<string|int, mixed>

fetch_field()

Fetches a row information from a query result and returns the values from that row as an array

public fetch_field(mixed $queryresult) : array<string|int, mixed>
Parameters
$queryresult : mixed
Return values
array<string|int, mixed>

fetch_my_query_status()

public fetch_my_query_status() : mixed
Return values
mixed

fetch_row()

Fetches a row from a query result and returns the values from that row as an array with numeric keys

public fetch_row(mixed $queryresult) : array<string|int, mixed>
Parameters
$queryresult : mixed
Return values
array<string|int, mixed>

fetchInTransaction()

tell whether we are currently in a transaction

public fetchInTransaction() : mixed
Return values
mixed

field_name()

Returns the name of a field from within a query result set

public field_name(mixed $queryresult, mixed $index) : string
Parameters
$queryresult : mixed
$index : mixed
Return values
string

force_sql_mode()

Forces the sql_mode varaible to a specific mode. Certain modes may be incompatible with vBulletin. Applies to MySQL 4.1+.

public force_sql_mode(mixed $mode) : mixed
Parameters
$mode : mixed
Return values
mixed

found_rows()

Executes a FOUND_ROWS query to get the results of SQL_CALC_FOUND_ROWS

public found_rows() : int
Return values
int

free_result()

Frees all memory associated with the specified query result

public free_result(mixed $queryresult) : bool
Parameters
$queryresult : mixed
Return values
bool

getCriticalErrors()

Function to return the codes of critical errors when testing if a database is a valid vB5 database - normally database not found and table not found errors.

public getCriticalErrors() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of error codes.

getExplain()

At the end of the request, this returns the generated "explain" output for display

public getExplain() : mixed
Return values
mixed

getInitialClientCharset()

Returns the *default* character encoding of the client which is not necesarily the one we are using.

public getInitialClientCharset() : mixed
Return values
mixed

halt()

Halts execution of the entire system and displays an error message

public halt([mixed $errortext = '' ]) : int
Parameters
$errortext : mixed = ''
Return values
int

hasConfigCharset()

Is there a charset explicitly set in the db config.

public hasConfigCharset() : mixed
Return values
mixed

hide_errors()

Switches database error display OFF

public hide_errors() : mixed
Return values
mixed

insert_id()

Returns the ID of the item just inserted into an auto-increment field

public insert_id() : int
Return values
int

insert_multiple()

Executes an INSERT or REPLACE query with multiple values, splitting large queries into manageable chunks based on $this->maxpacket

public insert_multiple(mixed $sql, mixed &$values, mixed $buffered) : mixed
Parameters
$sql : mixed
$values : mixed
$buffered : mixed
Return values
mixed

isExplainEmpty()

Checks if explain array is empty

public isExplainEmpty() : bool
Return values
bool

lock_tables()

Lock tables

public lock_tables(mixed $tablelist) : mixed
Parameters
$tablelist : mixed
Return values
mixed

num_fields()

Returns the number of fields contained within a query result set

public num_fields(mixed $queryresult) : int
Parameters
$queryresult : mixed
Return values
int

num_rows()

Returns the number of rows contained within a query result set

public num_rows(mixed $queryresult) : int
Parameters
$queryresult : mixed
Return values
int

ping()

Ping connection and reconnect Don't use this in a manner that could cause a loop condition

public ping() : mixed
Return values
mixed

query()

Executes an SQL query, using either the write connection

public query(mixed $sql[, mixed $buffered = true ]) : string
Parameters
$sql : mixed
$buffered : mixed = true
Tags
deprecated

Deprecated as of 3.6. Use query_(read/write)

Return values
string

query_first()

Executes a data-reading SQL query, then returns an array of the data from the first row from the result set

public query_first(mixed $sql[, mixed $type = self::DBARRAY_ASSOC ]) : array<string|int, mixed>
Parameters
$sql : mixed
$type : mixed = self::DBARRAY_ASSOC
Return values
array<string|int, mixed>

query_first_slave()

Executes a data-reading SQL query against the slave server, then returns an array of the data from the first row from the result set

public query_first_slave(mixed $sql[, mixed $type = self::DBARRAY_ASSOC ]) : array<string|int, mixed>
Parameters
$sql : mixed
$type : mixed = self::DBARRAY_ASSOC
Return values
array<string|int, mixed>

query_insert()

Executes an INSERT INTO query, using extended inserts if possible

public query_insert(mixed $table, mixed $fields, mixed &$values[, mixed $buffered = true ]) : mixed
Parameters
$table : mixed
$fields : mixed
$values : mixed
$buffered : mixed = true
Return values
mixed

query_read()

Executes a data-reading SQL query through the 'master' database connection we don't know if the 'read' database is up to date so be on the safe side

public query_read(mixed $sql[, mixed $buffered = true ]) : string
Parameters
$sql : mixed
$buffered : mixed = true
Return values
string

query_read_slave()

Executes a data-reading SQL query through the 'slave' database connection

public query_read_slave(mixed $sql[, mixed $buffered = true ]) : string
Parameters
$sql : mixed
$buffered : mixed = true
Return values
string

query_replace()

Executes a REPLACE INTO query, using extended inserts if possible

public query_replace(mixed $table, mixed $fields, mixed &$values[, mixed $buffered = true ]) : mixed
Parameters
$table : mixed
$fields : mixed
$values : mixed
$buffered : mixed = true
Return values
mixed

query_write()

Executes a data-writing SQL query through the 'master' database connection

public query_write(mixed $sql[, mixed $buffered = true ]) : string
Parameters
$sql : mixed
$buffered : mixed = true
Return values
string

rollbackTransaction()

Standard transaction handler.

public rollbackTransaction() : mixed
Return values
mixed

select_db()

Selects a database to use

public select_db([mixed $database = '' ]) : bool
Parameters
$database : mixed = ''
Return values
bool

select_db_using_dbconfig()

public select_db_using_dbconfig() : mixed
Return values
mixed

select_db_wrapper()

Simple wrapper for select_db(), to allow argument order changes

public select_db_wrapper([mixed $database = '' ][, mixed $link = null ]) : bool
Parameters
$database : mixed = ''
$link : mixed = null
Return values
bool

show_errors()

Switches database error display ON

public show_errors() : mixed
Return values
mixed

shutdown_query()

Registers an SQL query to be executed at shutdown time. If shutdown functions are disabled, the query is run immediately.

public shutdown_query(mixed $sql[, mixed $arraykey = -1 ]) : bool
Parameters
$sql : mixed
$arraykey : mixed = -1
Return values
bool

sql_prepare()

Takes a piece of data and prepares it to be put into an SQL query by adding quotes etc.

public sql_prepare(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

The prepared data

unlock_tables()

Unlock tables

public unlock_tables() : mixed
Return values
mixed

db_connect()

Initialize database connection(s)

protected db_connect(mixed $servername, mixed $port, mixed $username, mixed $password, mixed $usepconnect[, mixed $configfile = '' ]) : object

Connects to the specified master database server, and also to the slave server if it is specified

Parameters
$servername : mixed
$port : mixed
$username : mixed
$password : mixed
$usepconnect : mixed
$configfile : mixed = ''
Return values
object

Mysqli Resource

execute_query()

Executes an SQL query through the specified connection

protected execute_query(mixed $buffered, mixed &$link) : string
Parameters
$buffered : mixed
$link : mixed
Return values
string

postLogQueryToExplain()

Finishes logging a query for "explain" output, called after running the query

protected postLogQueryToExplain(mixed $index) : mixed
Parameters
$index : mixed
Return values
mixed

preLogQueryToExplain()

Initializes logging a query for "explain" output

protected preLogQueryToExplain() : int
Return values
int

Index of the current query in the explain output array

runExplainQuery()

Helper function used by getExplain to run the EXPLAIN query for the current query

protected runExplainQuery(mixed $sql) : string
Parameters
$sql : mixed
Return values
string

The formatted output for the EXPLAIN information for the query

set_charset()

protected set_charset(mixed $charset, mixed $link) : mixed
Parameters
$charset : mixed
$link : mixed
Return values
mixed

getErrorData()

private getErrorData([mixed $skipoptiondata = false ][, mixed $mysqlversion = '' ]) : mixed
Parameters
$skipoptiondata : mixed = false
$mysqlversion : mixed = ''
Return values
mixed

reset_db_connection()

private reset_db_connection() : mixed
Return values
mixed

Search results