class vB_Database_Slave_MySQLi extends vB_Database_MySQLi

Class to handle interacting with a slave (and master) DB. Slave DBs are used for some reads. Master DBs are used for all writes and time-sensitive reads. (MySQLi)

Traits

Constants

DBARRAY_BOTH

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

DBARRAY_ASSOC

DBARRAY_NUM

Properties

protected $inTransaction from vB_Database
array $functions Array of function names, mapping a simple name to the RDBMS specific function name from vB_Database_MySQLi
array $fetchtypes Array of constants for use in fetch_array from vB_Database_MySQLi
string $appname Full name of the system from vB_Database
string $appshortname Short name of the system from vB_Database
string $database Database name from vB_Database
string $connection_master Link variable. The connection to the master/write server. from vB_Database
string $connection_slave Link variable. The connection to the slave/read server(s). from vB_Database
string $connection_recent Link variable. The connection last used. from vB_Database
$multiserver from vB_Database
array $shutdownqueries Array of queries to be executed when the script shuts down from vB_Database
string $sql The contents of the most recent SQL query string. from vB_Database
boolean $reporterror Whether or not to show and halt on database errors from vB_Database
string $error The text of the most recent database error message from vB_Database
integer $errno The error number of the most recent database error message from vB_Database
integer $maxpacket SQL Query String from vB_Database
bool $locked Track lock status of tables. True if a table lock has been issued from vB_Database
integer $querycount Number of queries executed from vB_Database
bool $doExplain Whether or not to log the queries to generate query "explain" output from vB_Database
protected array $explain Array of information on each query, used for the "explain" output from vB_Database
protected array $phpTime Time information for queries, used by the "explain" output from vB_Database
protected $sqlTime from vB_Database
protected $startTime from vB_Database
protected $retries from vB_Database
protected array $dbconfig Reference to the sensitive database configuration array from class vB. Contains information required to connect to the database. from vB_Database

Methods

__sleep()

No description

__wakeup()

No description

__construct($dbconfig, $config)

vB_Database constructor.

none
connect(string $database, string $w_servername, integer $w_port, string $w_username, string $w_password, boolean $w_usepconnect = false, string $r_servername = '', integer $r_port = 3306, string $r_username = '', string $r_password = '', boolean $r_usepconnect = false, string $configfile = '', string $charset = '')

Connects to the specified database server(s)

set_charset($charset, $link)

No description

getInitialClientCharset()

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

hasConfigCharset()

Is there a charset explicitly set in the db config.

connect_using_dbconfig($override_config = array())

No description

select_db_using_dbconfig()

No description

beginTransaction()

Standard transaction handler.

rollbackTransaction()

Standard transaction handler.

fetchInTransaction()

tell whether we are currently in a transaction

commitTransaction()

Standard transaction handler.

boolean
db_connect($servername, $port, $username, $password, $usepconnect, $configfile = '')

Initialize database connection(s)

boolean
select_db(string $database = '')

Selects a database to use

boolean
select_db_wrapper(string $database = '', integer $link = null)

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

force_sql_mode(string $mode)

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

string
execute_query(boolean $buffered = true, string $link)

Executes an SQL query through the specified connection

string
query_write(string $sql, boolean $buffered = true)

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

string
query_read(string $sql, boolean $buffered = true)

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

string
query_read_slave(string $sql, boolean $buffered = true)

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

string
query(string $sql, boolean $buffered = true) deprecated

Executes an SQL query, using either the write connection

array
query_first(string $sql, string $type = self::DBARRAY_ASSOC)

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

integer
found_rows()

Executes a FOUND_ROWS query to get the results of SQL_CALC_FOUND_ROWS

array
query_first_slave(string $sql, string $type = vB_Database::DBARRAY_ASSOC)

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

mixed
query_insert(string $table, string $fields, array $values, boolean $buffered = true)

Executes an INSERT INTO query, using extended inserts if possible

mixed
query_replace(string $table, string $fields, array $values, boolean $buffered = true)

Executes a REPLACE INTO query, using extended inserts if possible

mixed
insert_multiple(string $sql, mixed $values, boolean $buffered)

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

boolean
shutdown_query(string $sql, mixed $arraykey = -1)

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

integer
num_rows(string $queryresult)

Returns the number of rows contained within a query result set

integer
num_fields(string $queryresult)

Returns the number of fields contained within a query result set

string
field_name(string $queryresult, integer $index)

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

integer
insert_id()

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

string
client_encoding()

Returns the name of the character set

integer
close()

Closes the connection to both the read database server

string
escape_string(string $string)

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

string
escape_string_like(string $string)

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

string
clean_identifier(string $identifier)

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

mixed
sql_prepare(mixed $value)

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

array
fetch_array(string $queryresult, integer $type = self::DBARRAY_ASSOC)

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

array
fetch_row(string $queryresult)

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

array
fetch_field(string $queryresult)

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

boolean
data_seek(string $queryresult, integer $index)

Moves the internal result pointer within a query result set

boolean
free_result(string $queryresult)

Frees all memory associated with the specified query result

integer
affected_rows()

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

ping()

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

lock_tables($tablelist)

Lock tables

unlock_tables()

Unlock tables

string
error()

Returns the text of the error message from previous database operation

integer
errno()

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

show_errors()

Switches database error display ON

hide_errors()

Switches database error display OFF

catch_db_error($errno, $errstr, $errfile, $errline)

No description

integer
halt(string $errortext = '')

Halts execution of the entire system and displays an error message

int
preLogQueryToExplain()

Initializes logging a query for "explain" output

postLogQueryToExplain(int $index)

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

getExplain()

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

string
runExplainQuery(string $sql)

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

array
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.

bool
isExplainEmpty()

Checks if explain array is empty

fetch_my_query_status()

No description

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

in vB_Database at line 212
__construct($dbconfig, $config)

vB_Database constructor.

Parameters

$dbconfig
$config

at line 159
none connect(string $database, string $w_servername, integer $w_port, string $w_username, string $w_password, boolean $w_usepconnect = false, string $r_servername = '', integer $r_port = 3306, string $r_username = '', string $r_password = '', boolean $r_usepconnect = false, string $configfile = '', string $charset = '')

Connects to the specified database server(s)

Parameters

string $database Name of the database that we will be using for select_db()
string $w_servername Name of the master (write) server - should be either 'localhost' or an IP address
integer $w_port Port for the master server
string $w_username Username to connect to the master server
string $w_password Password associated with the username for the master server
boolean $w_usepconnect Whether or not to use persistent connections to the master server
string $r_servername (Optional) Name of the slave (read) server - should be either left blank or set to 'localhost' or an IP address, but NOT the same as the servername for the master server
integer $r_port (Optional) Port of the slave server
string $r_username (Optional) Username to connect to the slave server
string $r_password (Optional) Password associated with the username for the slave server
boolean $r_usepconnect (Optional) Whether or not to use persistent connections to the slave server
string $configfile (Optional) Parse given MySQL config file to set options
string $charset (Optional) Connection Charset MySQLi / PHP 5.1.0+ or 5.0.5+ / MySQL 4.1.13+ or MySQL 5.1.10+ Only

Return Value

none

in vB_Database_MySQLi at line 111
protected set_charset($charset, $link)

Parameters

$charset
$link

in vB_Database_MySQLi at line 133
getInitialClientCharset()

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

in vB_Database at line 328
hasConfigCharset()

Is there a charset explicitly set in the db config.

in vB_Database at line 333
connect_using_dbconfig($override_config = array())

Parameters

$override_config

in vB_Database at line 355
create_database_using_dbconfig()

in vB_Database at line 385
select_db_using_dbconfig()

in vB_Database at line 393
beginTransaction()

Standard transaction handler.

in vB_Database at line 410
rollbackTransaction()

Standard transaction handler.

in vB_Database at line 426
fetchInTransaction()

tell whether we are currently in a transaction

in vB_Database at line 434
commitTransaction()

Standard transaction handler.

in vB_Database_MySQLi at line 81
protected boolean db_connect($servername, $port, $username, $password, $usepconnect, $configfile = '')

Initialize database connection(s)

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

Parameters

$servername
$port
$username
$password
$usepconnect
$configfile

Return Value

boolean

at line 192
boolean select_db(string $database = '')

Selects a database to use

Parameters

string $database The name of the database located on the database server(s)

Return Value

boolean

in vB_Database_MySQLi at line 216
boolean select_db_wrapper(string $database = '', integer $link = null)

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

Parameters

string $database Database name
integer $link Link identifier

Return Value

boolean

in vB_Database at line 517
force_sql_mode(string $mode)

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

Parameters

string $mode The mode to set the sql_mode variable to

in vB_Database_MySQLi at line 160
string execute_query(boolean $buffered = true, string $link)

Executes an SQL query through the specified connection

Parameters

boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is unbuffered.
string $link The connection ID to the database server

Return Value

string

in vB_Database at line 554
string query_write(string $sql, boolean $buffered = true)

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

Parameters

string $sql The text of the SQL query to be executed
boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is buffered.

Return Value

string

in vB_Database at line 569
string query_read(string $sql, boolean $buffered = true)

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

Parameters

string $sql The text of the SQL query to be executed
boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is buffered.

Return Value

string

at line 209
string query_read_slave(string $sql, boolean $buffered = true)

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

Parameters

string $sql The text of the SQL query to be executed
boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is buffered.

Return Value

string

in vB_Database at line 599
string query(string $sql, boolean $buffered = true) deprecated

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

Executes an SQL query, using either the write connection

Parameters

string $sql The text of the SQL query to be executed
boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is unbuffered.

Return Value

string

in vB_Database at line 613
array query_first(string $sql, string $type = self::DBARRAY_ASSOC)

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

Parameters

string $sql The text of the SQL query to be executed
string $type One of (NUM, ASSOC, BOTH)

Return Value

array

in vB_Database at line 627
integer found_rows()

Executes a FOUND_ROWS query to get the results of SQL_CALC_FOUND_ROWS

Return Value

integer

at line 223
array query_first_slave(string $sql, string $type = vB_Database::DBARRAY_ASSOC)

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

Parameters

string $sql The text of the SQL query to be executed
string $type One of (NUM, ASSOC, BOTH)

Return Value

array

in vB_Database at line 664
mixed query_insert(string $table, string $fields, array $values, boolean $buffered = true)

Executes an INSERT INTO query, using extended inserts if possible

Parameters

string $table Name of the table into which data should be inserted
string $fields Comma-separated list of the fields to affect
array $values Array of SQL values
boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is unbuffered.

Return Value

mixed

in vB_Database at line 679
mixed query_replace(string $table, string $fields, array $values, boolean $buffered = true)

Executes a REPLACE INTO query, using extended inserts if possible

Parameters

string $table Name of the table into which data should be inserted
string $fields Comma-separated list of the fields to affect
array $values Array of SQL values
boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is unbuffered.

Return Value

mixed

in vB_Database at line 693
mixed insert_multiple(string $sql, mixed $values, boolean $buffered)

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

Parameters

string $sql The text of the first part of the SQL query to be executed - example "INSERT INTO table (field1, field2) VALUES"
mixed $values The values to be inserted. Example: (0 => "('value1', 'value2')", 1 => "('value3', 'value4')")
boolean $buffered Whether or not to run this query buffered (true) or unbuffered (false). Default is unbuffered.

Return Value

mixed

in vB_Database at line 750
boolean shutdown_query(string $sql, mixed $arraykey = -1)

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

Parameters

string $sql The text of the SQL query to be executed
mixed $arraykey (Optional) Allows particular shutdown queries to be labelled

Return Value

boolean

in vB_Database at line 771
integer num_rows(string $queryresult)

Returns the number of rows contained within a query result set

Parameters

string $queryresult The query result ID we are dealing with

Return Value

integer

in vB_Database at line 783
integer num_fields(string $queryresult)

Returns the number of fields contained within a query result set

Parameters

string $queryresult The query result ID we are dealing with

Return Value

integer

in vB_Database_MySQLi at line 253
string field_name(string $queryresult, integer $index)

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

Parameters

string $queryresult The query result ID we are dealing with
integer $index The index position of the field

Return Value

string

in vB_Database at line 806
integer insert_id()

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

Return Value

integer

in vB_Database at line 816
string client_encoding()

Returns the name of the character set

Return Value

string

at line 237
integer close()

Closes the connection to both the read database server

Return Value

integer

in vB_Database_MySQLi at line 228
string escape_string(string $string)

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

Parameters

string $string The string to be escaped

Return Value

string

in vB_Database at line 858
string escape_string_like(string $string)

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

Parameters

string $string The string to be escaped

Return Value

string

in vB_Database_MySQLi at line 240
string clean_identifier(string $identifier)

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

Parameters

string $identifier The string to be cleaned

Return Value

string

in vB_Database at line 882
mixed sql_prepare(mixed $value)

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

Parameters

mixed $value The data to be used

Return Value

mixed The prepared data

in vB_Database at line 912
array fetch_array(string $queryresult, integer $type = self::DBARRAY_ASSOC)

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

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

Parameters

string $queryresult The query result ID we are dealing with
integer $type One of self::DBARRAY_ASSOC / self::DBARRAY_NUM / self::DBARRAY_BOTH

Return Value

array

in vB_Database at line 925
array fetch_row(string $queryresult)

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

Parameters

string $queryresult The query result ID we are dealing with

Return Value

array

in vB_Database at line 938
array fetch_field(string $queryresult)

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

Parameters

string $queryresult The query result ID we are dealing with

Return Value

array

in vB_Database at line 952
boolean data_seek(string $queryresult, integer $index)

Moves the internal result pointer within a query result set

Parameters

string $queryresult The query result ID we are dealing with
integer $index The position to which to move the pointer (first position is 0)

Return Value

boolean

in vB_Database at line 964
boolean free_result(string $queryresult)

Frees all memory associated with the specified query result

Parameters

string $queryresult The query result ID we are dealing with

Return Value

boolean

in vB_Database at line 975
integer affected_rows()

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

Return Value

integer

in vB_Database_MySQLi at line 282
ping()

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

in vB_Database_MySQLi at line 314
lock_tables($tablelist)

Lock tables

Parameters

$tablelist

in vB_Database at line 1041
unlock_tables()

Unlock tables

in vB_Database at line 1054
string error()

Returns the text of the error message from previous database operation

Return Value

string

in vB_Database_MySQLi at line 329
integer errno()

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

Return Value

integer

in vB_Database_MySQLi at line 262
show_errors()

Switches database error display ON

in vB_Database_MySQLi at line 271
hide_errors()

Switches database error display OFF

in vB_Database at line 1104
catch_db_error($errno, $errstr, $errfile, $errline)

Parameters

$errno
$errstr
$errfile
$errline

in vB_Database at line 1144
integer halt(string $errortext = '')

Halts execution of the entire system and displays an error message

Parameters

string $errortext Text of the error message. Leave blank to use $this->sql as error text.

Return Value

integer

in vB_Database at line 1293
protected int preLogQueryToExplain()

Initializes logging a query for "explain" output

Return Value

int Index of the current query in the explain output array

in vB_Database at line 1327
protected postLogQueryToExplain(int $index)

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

Parameters

int $index Index of the current query in the explain output array

in vB_Database at line 1347
getExplain()

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

in vB_Database_MySQLi at line 367
protected string runExplainQuery(string $sql)

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

Parameters

string $sql The current SQL query

Return Value

string The formatted output for the EXPLAIN information for the query

in vB_Database_MySQLi at line 402
array 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.

Return Value

array An array of error codes.

in vB_Database at line 1463
bool isExplainEmpty()

Checks if explain array is empty

Return Value

bool

in vB_Database at line 1468
fetch_my_query_status()