Class vB_Database

Description

Class to interface with a database

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

  • version: $Revision: 35065 $
  • date: $Date: 2010-01-21 14:01:23 -0600 (Thu, 21 Jan 2010) $

Located in /includes/class_core.php (line 79)


	
			
Direct descendents
Class Description
 class vB_Database_MySQLi Class to interface with a MySQL 4.1 database
 class vB_Database_Explain Class to interface with a database
 class vB_Database_Slave 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.
Variable Summary
 string $appname
 string $appshortname
 string $database
 integer $errno
 string $error
 array $fetchtypes
 array $functions
 bool $locked
 integer $maxpacket
 boolean $multiserver
 integer $querycount
 boolean $reporterror
 string $sql
Method Summary
 vB_Database vB_Database (vB_Registry &$registry)
 integer affected_rows ()
 string client_encoding ()
 integer close ()
 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 = ''])
 boolean data_seek (string $queryresult, integer $index)
 boolean db_connect (string $servername, integer $port, string $username, string $password, boolean $usepconnect, [string $configfile = ''], [string $charset = ''])
 integer errno ()
 string error ()
 string escape_string (string $string)
 string escape_string_like (string $string)
 string &execute_query ([boolean $buffered = true], string &$link)
 array fetch_array (string $queryresult, [integer $type = DBARRAY_ASSOC])
 array fetch_field (string $queryresult)
 array fetch_row (string $queryresult)
 string field_name (string $queryresult, integer $index)
 void force_sql_mode (string $mode)
 integer found_rows ()
 boolean free_result (string $queryresult)
 integer halt ([string $errortext = ''])
 void hide_errors ()
 integer insert_id ()
 mixed insert_multiple (string $sql, mixed &$values, boolean $buffered)
 void lock_tables (mixed $tablelist, string 1)
 integer num_fields (string $queryresult)
 integer num_rows (string $queryresult)
 string query (string $sql, [boolean $buffered = true])
 array &query_first (string $sql, [string $type = DBARRAY_ASSOC])
 array &query_first_slave (string $sql, [string $type = DBARRAY_ASSOC])
 mixed &query_insert (string $table, string $fields, array &$values, [boolean $buffered = true])
 string query_read (string $sql, [boolean $buffered = true])
 string query_read_slave (string $sql, [boolean $buffered = true])
 mixed &query_replace (string $table, string $fields, array &$values, [boolean $buffered = true])
 string query_write (string $sql, [boolean $buffered = true])
 boolean select_db ([string $database = ''])
 boolean select_db_wrapper ([string $database = ''], [integer $link = null])
 void show_errors ()
 boolean shutdown_query (string $sql, [mixed $arraykey = -1])
 mixed sql_prepare (mixed $value)
 void unlock_tables ()
Variables
string $appname = 'vBulletin' (line 133)

Full name of the system

string $appshortname = 'vBulletin' (line 140)

Short name of the system

string $connection_master = null (line 154)

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

string $connection_recent = null (line 168)

Link variable. The connection last used.

string $connection_slave = null (line 161)

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

string $database = null (line 147)

Database name

integer $errno = '' (line 210)

The error number of the most recent database error message

string $error = '' (line 203)

The text of the most recent database error message

array $fetchtypes = array(
DBARRAY_NUM => MYSQL_NUM,
DBARRAY_ASSOC => MYSQL_ASSOC,
DBARRAY_BOTH => MYSQL_BOTH
)
(line 122)

Array of constants for use in fetch_array


Redefined in descendants as:
array $functions = array(
'connect' => 'mysql_connect',
'pconnect' => 'mysql_pconnect',
'select_db' => 'mysql_select_db',
'query' => 'mysql_query',
'query_unbuffered' => 'mysql_unbuffered_query',
'fetch_row' => 'mysql_fetch_row',
'fetch_array' => 'mysql_fetch_array',
'fetch_field' => 'mysql_fetch_field',
'free_result' => 'mysql_free_result',
'data_seek' => 'mysql_data_seek',
'error' => 'mysql_error',
'errno' => 'mysql_errno',
'affected_rows' => 'mysql_affected_rows',
'num_rows' => 'mysql_num_rows',
'num_fields' => 'mysql_num_fields',
'field_name' => 'mysql_field_name',
'insert_id' => 'mysql_insert_id',
'escape_string' => 'mysql_escape_string',
'real_escape_string' => 'mysql_real_escape_string',
'close' => 'mysql_close',
'client_encoding' => 'mysql_client_encoding',
)
(line 86)

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


Redefined in descendants as:
bool $locked = false (line 224)

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

integer $maxpacket = 0 (line 217)

SQL Query String

  • var: The maximum size of query string permitted by the master server
boolean $multiserver = false (line 175)

Whether or not we will be using different connections for read and write queries

integer $querycount = 0 (line 231)

Number of queries executed

  • var: The number of SQL queries run by the system
vB_Registry $registry = null (line 115)

The vBulletin registry object

boolean $reporterror = true (line 196)

Whether or not to show and halt on database errors

array $shutdownqueries = array() (line 182)

Array of queries to be executed when the script shuts down

string $sql = '' (line 189)

The contents of the most recent SQL query string.

Methods
Constructor vB_Database (line 239)

Constructor. If x_real_escape_string() is available, switches to use that function over x_escape_string().

vB_Database vB_Database (vB_Registry &$registry)
affected_rows (line 919)

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

integer affected_rows ()
client_encoding (line 695)

Returns the name of the character set

string client_encoding ()
close (line 705)

Closes the connection to the database server

integer close ()

Redefined in descendants as:
connect (line 270)

Connects to the specified database server(s)

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 = ''])
  • 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

Redefined in descendants as:
data_seek (line 896)

Moves the internal result pointer within a query result set

boolean data_seek (string $queryresult, integer $index)
  • string $queryresult: The query result ID we are dealing with
  • integer $index: The position to which to move the pointer (first position is 0)
db_connect (line 302)

Initialize database connection(s)

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

boolean db_connect (string $servername, integer $port, string $username, string $password, boolean $usepconnect, [string $configfile = ''], [string $charset = ''])
  • string $servername: Name of the database server - should be either 'localhost' or an IP address
  • integer $port: Port of the database server (usually 3306)
  • string $username: Username to connect to the database server
  • string $password: Password associated with the username for the database server
  • boolean $usepconnect: Whether or not to use persistent connections to the database server
  • string $configfile: Not applicable; config file for MySQLi only
  • string $charset: Force connection character set (to prevent collation errors)

Redefined in descendants as:
errno (line 992)

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

integer errno ()
error (line 974)

Returns the text of the error message from previous database operation

string error ()
escape_string (line 717)

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

string escape_string (string $string)
  • string $string: The string to be escaped

Redefined in descendants as:
escape_string_like (line 736)

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

string escape_string_like (string $string)
  • string $string: The string to be escaped
execute_query (line 407)

Executes an SQL query through the specified connection

string &execute_query ([boolean $buffered = true], string &$link)
  • 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

Redefined in descendants as:
fetch_array (line 778)

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

array fetch_array (string $queryresult, [integer $type = DBARRAY_ASSOC])
  • string $queryresult: The query result ID we are dealing with
  • integer $type: One of DBARRAY_ASSOC / DBARRAY_NUM / DBARRAY_BOTH
fetch_field (line 856)

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

array fetch_field (string $queryresult)
  • string $queryresult: The query result ID we are dealing with
fetch_row (line 817)

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

array fetch_row (string $queryresult)
  • string $queryresult: The query result ID we are dealing with
field_name (line 675)

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

string field_name (string $queryresult, integer $index)
  • string $queryresult: The query result ID we are dealing with
  • integer $index: The index position of the field

Redefined in descendants as:
force_sql_mode (line 383)

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

void force_sql_mode (string $mode)
  • string $mode: The mode to set the sql_mode variable to
found_rows (line 509)

Executes a FOUND_ROWS query to get the results of SQL_CALC_FOUND_ROWS

integer found_rows ()
free_result (line 908)

Frees all memory associated with the specified query result

boolean free_result (string $queryresult)
  • string $queryresult: The query result ID we are dealing with
halt (line 1028)

Halts execution of the entire system and displays an error message

integer halt ([string $errortext = ''])
  • string $errortext: Text of the error message. Leave blank to use $this->sql as error text.
hide_errors (line 1016)

Switches database error display OFF

void hide_errors ()
insert_id (line 685)

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

integer insert_id ()
insert_multiple (line 572)

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

mixed insert_multiple (string $sql, mixed &$values, boolean $buffered)
  • 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.
lock_tables (line 932)

Lock tables

void lock_tables (mixed $tablelist, string 1)
  • string 1: Type of lock to perform
  • mixed $tablelist: List of tables to lock
num_fields (line 662)

Returns the number of fields contained within a query result set

integer num_fields (string $queryresult)
  • string $queryresult: The query result ID we are dealing with
num_rows (line 650)

Returns the number of rows contained within a query result set

integer num_rows (string $queryresult)
  • string $queryresult: The query result ID we are dealing with
query (line 481)

Executes an SQL query, using either the write connection

  • deprecated: Deprecated as of 3.6. Use query_(read/write)
string query (string $sql, [boolean $buffered = true])
  • 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.
query_first (line 495)

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

array &query_first (string $sql, [string $type = DBARRAY_ASSOC])
  • string $sql: The text of the SQL query to be executed
  • string $type: One of (NUM, ASSOC, BOTH)
query_first_slave (line 527)

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

array &query_first_slave (string $sql, [string $type = DBARRAY_ASSOC])
  • string $sql: The text of the SQL query to be executed
  • string $type: One of (NUM, ASSOC, BOTH)

Redefined in descendants as:
query_insert (line 543)

Executes an INSERT INTO query, using extended inserts if possible

mixed &query_insert (string $table, string $fields, array &$values, [boolean $buffered = true])
  • 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.
query_read (line 451)

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 (string $sql, [boolean $buffered = true])
  • 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.
query_read_slave (line 465)

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

string query_read_slave (string $sql, [boolean $buffered = true])
  • 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.

Redefined in descendants as:
query_replace (line 558)

Executes a REPLACE INTO query, using extended inserts if possible

mixed &query_replace (string $table, string $fields, array &$values, [boolean $buffered = true])
  • 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.
query_write (line 436)

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

string query_write (string $sql, [boolean $buffered = true])
  • 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.
select_db (line 341)

Selects a database to use

boolean select_db ([string $database = ''])
  • string $database: The name of the database located on the database server(s)

Redefined in descendants as:
select_db_wrapper (line 372)

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

boolean select_db_wrapper ([string $database = ''], [integer $link = null])
  • string $database: Database name
  • integer $link: Link identifier

Redefined in descendants as:
show_errors (line 1008)

Switches database error display ON

void show_errors ()
shutdown_query (line 629)

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

boolean shutdown_query (string $sql, [mixed $arraykey = -1])
  • string $sql: The text of the SQL query to be executed
  • mixed $arraykey: (Optional) Allows particular shutdown queries to be labelled
sql_prepare (line 748)

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

  • return: The prepared data
mixed sql_prepare (mixed $value)
  • mixed $value: The data to be used
unlock_tables (line 959)

Unlock tables

void unlock_tables ()

Documentation generated on Tue, 26 Jan 2010 15:15:05 -0600 by phpDocumentor 1.4.3