vB_Database
in package
Uses
vB_Trait_NoSerialize
Class to interface with a database
This class also handles data replication between a master and slave(s) servers
Table of Contents
Constants
- DBARRAY_ASSOC = 1
- DBARRAY_BOTH = 0
- The type of result set to return from the database for a specific row.
- DBARRAY_NUM = 2
Properties
- $appname : string
- Full name of the system
- $appshortname : string
- Short name of the system
- $connection_recent : mysqli
- Link variable. The connection last used.
- $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
- $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.
Methods
- __construct() : mixed
- vB_Database constructor.
- __serialize() : array<string|int, mixed>
- __sleep() : array<string|int, mixed>
- __unserialize() : void
- __wakeup() : void
- 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
- getExplain() : mixed
- At the end of the request, this returns the generated "explain" output for display
- 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
- is_install_valid() : mixed
- is_valid() : mixed
- 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.
- unlock_tables() : mixed
- Unlock tables
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
= 0
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_recent
Link variable. The connection last used.
public
mysqli
$connection_recent
= \null
$database
Database name
public
string
$database
= \null
$doExplain
Whether or not to log the queries to generate query "explain" output
public
bool
$doExplain
= \false
$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
= ''
$locked
Track lock status of tables. True if a table lock has been issued
public
bool
$locked
= \false
$maxpacket
SQL Query String
public
int
$maxpacket
= 0
The maximum size of query string permitted by the master server
$multiserver
public
mixed
$multiserver
= \false
$querycount
Number of queries executed
public
int
$querycount
= 0
The number of SQL queries run by the system
$reporterror
Whether or not to show and halt on database errors
public
bool
$reporterror
= \true
$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
= ''
Methods
__construct()
vB_Database constructor.
public
__construct(mixed &$dbconfig, mixed &$config) : mixed
Parameters
- $dbconfig : mixed
- $config : mixed
__serialize()
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__sleep()
public
__sleep() : array<string|int, mixed>
Return values
array<string|int, mixed>__unserialize()
public
__unserialize(array<string|int, mixed> $serialized) : void
Parameters
- $serialized : array<string|int, mixed>
__wakeup()
public
__wakeup() : void
affected_rows()
Retuns the number of rows affected by the most recent insert/replace/update query
public
affected_rows() : int
Return values
intbeginTransaction()
Standard transaction handler.
public
beginTransaction() : 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
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
stringclient_encoding()
Returns the name of the character set
public
client_encoding() : string
Return values
stringclose()
Closes the connection to the database server
public
close() : int
Return values
intcommitTransaction()
Standard transaction handler.
public
commitTransaction() : 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
noneconnect_using_dbconfig()
public
connect_using_dbconfig([mixed $override_config = [] ]) : mixed
Parameters
- $override_config : mixed = []
create_database_using_dbconfig()
public
create_database_using_dbconfig() : 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
boolerrno()
Returns the numerical value of the error message from previous database operation
public
errno() : int
Return values
interror()
Returns the text of the error message from previous database operation
public
error() : string
Return values
stringescape_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
stringescape_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
stringfetch_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
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
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
stringforce_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
found_rows()
Executes a FOUND_ROWS query to get the results of SQL_CALC_FOUND_ROWS
public
found_rows() : int
Return values
intfree_result()
Frees all memory associated with the specified query result
public
free_result(mixed $queryresult) : bool
Parameters
- $queryresult : mixed
Return values
boolgetExplain()
At the end of the request, this returns the generated "explain" output for display
public
getExplain() : mixed
hasConfigCharset()
Is there a charset explicitly set in the db config.
public
hasConfigCharset() : mixed
hide_errors()
Switches database error display OFF
public
hide_errors() : mixed
insert_id()
Returns the ID of the item just inserted into an auto-increment field
public
insert_id() : int
Return values
intinsert_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
is_install_valid()
public
is_install_valid() : mixed
is_valid()
public
is_valid() : mixed
isExplainEmpty()
Checks if explain array is empty
public
isExplainEmpty() : bool
Return values
boollock_tables()
Lock tables
public
lock_tables(mixed $tablelist) : mixed
Parameters
- $tablelist : 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
intnum_rows()
Returns the number of rows contained within a query result set
public
num_rows(mixed $queryresult) : int
Parameters
- $queryresult : mixed
Return values
intping()
Ping connection and reconnect Don't use this in a manner that could cause a loop condition
public
ping() : 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
Return values
stringquery_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
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
stringquery_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
stringquery_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
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
stringrollbackTransaction()
Standard transaction handler.
public
rollbackTransaction() : mixed
select_db()
Selects a database to use
public
select_db([mixed $database = '' ]) : bool
Parameters
- $database : mixed = ''
Return values
boolselect_db_using_dbconfig()
public
select_db_using_dbconfig() : 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
boolshow_errors()
Switches database error display ON
public
show_errors() : 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
boolunlock_tables()
Unlock tables
public
unlock_tables() : mixed