MySQL
extends DatabaseApi
in package
implements
DatabaseApiInterface
Interacts with MySQL databases.
Table of Contents
Interfaces
- DatabaseApiInterface
- Interface DatabaseApiInterface
Properties
- $cache : array<string|int, mixed>
- $case_sensitive : bool
- $character_set : string
- $connection : object
- $count : int
- $db : object
- $db_connection : object
- $disableQueryCheck : bool
- $mb4 : bool
- $name : string
- $package_log : array<string|int, mixed>
- $persist : bool
- $port : int
- $prefix : string
- $server : string
- $show_debug : bool
- $support_ignore : bool
- $supports_pcre : bool
- $sybase : bool
- $title : string
- $unbuffered : bool
- $engines : array<string|int, mixed>
- $error_data_prep : object
- $reservedTables : array<string|int, mixed>
- $supports_cte : bool
- $temp_connection : object
- $temp_values : array<string|int, mixed>
- $vendor : string
- $version : string
- $backcompat : array<string|int, mixed>
Methods
- add_column() : bool
- This function adds a column.
- add_index() : bool
- Add an index.
- affected_rows() : int
- Gets the number of rows affected by the last query.
- allow_persistent() : bool
- Figures out if persistent connection is allowed
- backup_table() : resource|false
- Backup $table to $backup_table.
- calculate_type() : array<string|int, mixed>
- Get the schema formatted name for a type.
- change_column() : bool
- Change a column. You only need to specify the column attributes that are changing.
- connect_errno() : int
- Gets the error code of last connection error.
- connect_error() : string
- Gets a description of the last connection error.
- create_table() : bool
- This function can be used to create a table without worrying about schema compatibilities across supported database systems.
- create_word_search() : void
- Highly specific function, to create the custom word index table.
- cte_support() : bool
- Function which return the information if the database supports cte with recursive
- custom_order() : string
- Function which constructs an optimize custom order string as an improved alternative to find_in_set()
- data_seek() : bool
- Adjusts the result pointer to an arbitrary row in a query result.
- drop_table() : bool
- Drop a table.
- error() : string
- Get the last error message string.
- error_insert() : void
- Save errors in the database safely.
- escape_string() : string
- Escapes special characters in a string for use in an SQL statement, taking into account the current character set of the connection.
- escape_wildcard_string() : string
- Escape the LIKE wildcards so that they match the character and not the wildcard.
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- fetch_all() : array<string|int, mixed>
- Fetches all rows from a result as an array.
- fetch_assoc() : array<string|int, mixed>
- Fetch the next row of a result set as an associative array.
- fetch_object() : object|false|null
- Fetches all rows from a result as an object.
- fetch_row() : array<string|int, mixed>|false
- Fetch the next row of a result set as an enumerated array.
- free_result() : bool
- Frees the memory and data associated with the query result.
- get_vendor() : string
- Figures out if we are using MySQL, Percona or MariaDB
- get_version() : string
- Get the version number.
- getClass() : string
- insert() : int|array<string|int, mixed>|null
- Inserts one or more rows of data into a database table and optionally returns the resulting IDs.
- insert_id() : int
- Gets the ID of the most recently inserted row.
- is_resource() : bool
- Validates whether the resource is a valid mysqli instance.
- list_columns() : array<string|int, mixed>
- Return column information for a table.
- list_indexes() : array<string|int, mixed>
- Get index information.
- list_tables() : array<string|int, mixed>
- This function lists all tables in the database.
- load() : object
- Static method used to instantiate the child class specified by Config::$db_type.
- native_replace() : bool
- Function which return the information if the database supports native replace inserts
- num_fields() : int
- Gets the number of fields in a result set.
- num_rows() : int
- Gets the number of rows in a result set.
- optimize_table() : int
- This function optimizes a table.
- ping() : bool
- Pings a server connection, and tries to reconnect if necessary.
- query() : object|bool
- Performs a query. Takes care of errors too.
- quote() : string
- Prepares a query string for execution, but does not perform the query.
- remove_column() : bool
- Removes a column.
- remove_index() : bool
- Remove an index.
- search_language() : string|null
- Return the language for the textsearch index
- search_query() : resource
- Returns the correct query for this search type.
- search_support() : bool
- This function will tell you whether this database type supports this search type.
- select() : bool
- Selects the default database for database queries.
- server_info() : string
- Gets information, such as the version, about the database server.
- table_sql() : string
- Dumps the schema (CREATE) for a table.
- table_structure() : array<string|int, mixed>
- Get table structure.
- transaction() : bool
- Do a transaction.
- unescape_string() : string
- Reverses the escape_string function.
- update_from() : bool
- Updates data in a table, using data from other tables.
- __construct() : mixed
- Constructor.
- create_query_column() : string
- Creates a query for a column
- error_backtrace() : void|array<string|int, mixed>
- This function tries to work out additional error information from a back trace.
- initiate() : void
- Initiates a connection to a database.
- mapToSmcFunc() : void
- For backward compatibility, make various public methods available as Utils::$smcFunc functions.
- prefixReservedTables() : void
- Appends the correct prefix to the reserved tables' names.
- replacement__callback() : string
- Callback for preg_replace_callback on the query.
Properties
$cache
public
static array<string|int, mixed>
$cache
= []
Records debugging info when $this->show_debug is true.
For backward compatibility, also referenced as global $db_cache.
$case_sensitive
public
bool
$case_sensitive
= false
Whether database is case sensitive.
$character_set
public
string
$character_set
Local copy of Config::$db_character_set.
$connection
public
object
$connection
The database connection object (mysqli or PgSql\Connection).
$count
public
static int
$count
= 0
The number of queries that have been run.
For backward compatibility, also referenced as global $db_count.
$db
public
static object
$db
A loaded instance of a child class of this class.
$db_connection
public
static object
$db_connection
A static copy of $this->connection. This exists solely to facilitate backward compatibility by populating the global $db_connection variable. Once such backward compatibility is no longer required in future versions of SMF, this variable can be completely removed from this class.
If multiple DatabaseApi instances are created, this static variable will always be a reference to the first instance's local $connection object. It will not be overwritten by later instances.
$disableQueryCheck
public
bool
$disableQueryCheck
Local copy of Config::$modSettings['disableQueryCheck'].
$mb4
public
bool
$mb4
Whether the database supports 4-byte UTF-8 characters.
For PostgreSQL, this will always be set to true. For MySQL, this will be set to the value of the Config::$db_mb4.
Tags
$name
public
string
$name
Local copy of Config::$db_name.
$package_log
public
static array<string|int, mixed>
$package_log
= []
Tracks package install/uninstall actions as they are performed.
For backward compatibility, also referenced as global $db_package_log.
$persist
public
bool
$persist
Local copy of Config::$db_persist.
$port
public
int
$port
Local copy of Config::$db_port.
$prefix
public
string
$prefix
Local copy of Config::$db_prefix.
$server
public
string
$server
Local copy of Config::$db_server.
$show_debug
public
bool
$show_debug
Local copy of Config::$db_show_debug.
$support_ignore
public
bool
$support_ignore
= true
Whether the database translation layer can accept INSERT IGNORE queries. MySQL does natively. PostgreSQL does not natively, but our PostgreSQL layer can rewrite such queries into an alternative syntax, so this will be true for both.
$supports_pcre
public
bool
$supports_pcre
= false
Whether the database supports PCRE regular expressions. Always true for PostgreSQL. Depends on version for MySQL.
$sybase
public
bool
$sybase
= false
Describes the database's method for escaping single quotes.
If false, escapes by using backslashes (i.e. \'
).
If true, escapes by doubling them (i.e. ''
).
$title
public
string
$title
= MYSQL_TITLE
Value of the appropriate *_TITLE constant.
$unbuffered
public
static bool
$unbuffered
= false
Force unbuffered output. Only applicable to MySQL.
$engines
protected
array<string|int, mixed>
$engines
= []
Available MySQL engines.
$error_data_prep
protected
object
$error_data_prep
A prepared MySQL statement (a mysqli_stmt object).
$reservedTables
protected
array<string|int, mixed>
$reservedTables
= ['admin_info_files', 'approval_queue', 'attachments', 'background_tasks', 'ban_groups', 'ban_items', 'board_permissions', 'board_permissions_view', 'boards', 'calendar', 'categories', 'custom_fields', 'group_moderators', 'log_actions', 'log_activity', 'log_banned', 'log_boards', 'log_comments', 'log_digest', 'log_errors', 'log_floodcontrol', 'log_group_requests', 'log_mark_read', 'log_member_notices', 'log_notify', 'log_online', 'log_packages', 'log_polls', 'log_reported', 'log_reported_comments', 'log_scheduled_tasks', 'log_search_messages', 'log_search_results', 'log_search_subjects', 'log_search_topics', 'log_spider_hits', 'log_spider_stats', 'log_subscribed', 'log_topics', 'mail_queue', 'member_logins', 'membergroups', 'members', 'mentions', 'message_icons', 'messages', 'moderator_groups', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', 'pm_labeled_messages', 'pm_labels', 'pm_recipients', 'pm_rules', 'poll_choices', 'polls', 'qanda', 'scheduled_tasks', 'sessions', 'settings', 'smiley_files', 'smileys', 'spiders', 'subscriptions', 'themes', 'topics', 'user_alerts', 'user_alerts_prefs', 'user_drafts', 'user_likes']
SMF tables that can't be auto-removed - in case a mod writer cocks it up!
$supports_cte
protected
bool
$supports_cte
Whether this version of MySQL has CTE support.
$temp_connection
protected
object
$temp_connection
Temporary reference to a mysqli object. Might be the same as $this->connection, but might not be. Used to pass the correct connection to $this->replace__callback.
$temp_values
protected
array<string|int, mixed>
$temp_values
Used to pass values to $this->replace__callback.
$vendor
protected
string
$vendor
Vendor of this particular variant of MySQL.
$version
protected
string
$version
MySQL version string.
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['prop_names' => ['count' => 'db_count', 'cache' => 'db_cache', 'package_log' => 'db_package_log', 'db_connection' => 'db_connection']]
BackwardCompatibility settings for this class.
Methods
add_column()
This function adds a column.
public
add_column(string $table_name, array<string|int, mixed> $column_info[, array<string|int, mixed> $parameters = [] ][, string $if_exists = 'update' ][, string $error = 'fatal' ]) : bool
Parameters
- $table_name : string
-
The name of the table to add the column to
- $column_info : array<string|int, mixed>
-
An array of column info (smf_db_create_table)
- $parameters : array<string|int, mixed> = []
-
Not used?
- $if_exists : string = 'update'
-
What to do if the column exists. If 'update', column is updated.
- $error : string = 'fatal'
Return values
bool —Whether or not the operation was successful
add_index()
Add an index.
public
add_index(string $table_name, array<string|int, mixed> $index_info[, array<string|int, mixed> $parameters = [] ][, string $if_exists = 'update' ][, string $error = 'fatal' ]) : bool
Parameters
- $table_name : string
-
The name of the table to add the index to
- $index_info : array<string|int, mixed>
-
- $parameters : array<string|int, mixed> = []
-
Not used?
- $if_exists : string = 'update'
-
What to do if the index exists. If 'update', the definition will be updated.
- $error : string = 'fatal'
Return values
bool —Whether or not the operation was successful
affected_rows()
Gets the number of rows affected by the last query.
public
affected_rows([object|null $connection = null ]) : int
Parameters
- $connection : object|null = null
-
A connection to use (if null, $db_connection is used)
Return values
int —The number of affected rows.
allow_persistent()
Figures out if persistent connection is allowed
public
allow_persistent() : bool
Return values
boolbackup_table()
Backup $table to $backup_table.
public
backup_table(string $table, string $backup_table) : resource|false
Parameters
- $table : string
-
The name of the table to backup
- $backup_table : string
-
The name of the backup table for this table
Return values
resource|false —-the request handle to the table creation query, false if it failed.
calculate_type()
Get the schema formatted name for a type.
public
calculate_type(string $type_name[, int|null $type_size = null ][, bool $reverse = false ]) : array<string|int, mixed>
Parameters
- $type_name : string
-
The data type (int, varchar, smallint, etc.)
- $type_size : int|null = null
-
The size (8, 255, etc.)
- $reverse : bool = false
Return values
array<string|int, mixed> —An array containing the appropriate type and size for this DB type
change_column()
Change a column. You only need to specify the column attributes that are changing.
public
change_column(string $table_name, string $old_column, array<string|int, mixed> $column_info) : bool
Parameters
- $table_name : string
-
The name of the table this column is in
- $old_column : string
-
The name of the column we want to change
- $column_info : array<string|int, mixed>
-
An array of info about the "new" column definition (see ) Note that $column_info also supports two additional parameters that only make sense when changing columns:
- drop_default - to drop a default that was previously specified
Return values
boolconnect_errno()
Gets the error code of last connection error.
public
connect_errno() : int
Return values
int —Error code from the last connection attempt.
connect_error()
Gets a description of the last connection error.
public
connect_error() : string
Return values
string —Error message from the last connection attempt.
create_table()
This function can be used to create a table without worrying about schema compatibilities across supported database systems.
public
create_table(string $table_name, array<string|int, mixed> $columns[, array<string|int, mixed> $indexes = [] ][, array<string|int, mixed> $parameters = [] ][, string $if_exists = 'ignore' ][, string $error = 'fatal' ]) : bool
Parameters
- $table_name : string
-
The name of the table to create
- $columns : array<string|int, mixed>
-
An array of column info in the specified format
- $indexes : array<string|int, mixed> = []
-
An array of index info in the specified format
- $parameters : array<string|int, mixed> = []
-
Extra parameters. Currently only 'engine', the desired MySQL storage engine, is used.
- $if_exists : string = 'ignore'
-
What to do if the table exists.
- $error : string = 'fatal'
Return values
bool —Whether or not the operation was successful
create_word_search()
Highly specific function, to create the custom word index table.
public
create_word_search(string $size) : void
Parameters
- $size : string
-
The column size type (int, mediumint (8), etc.). Not used here.
cte_support()
Function which return the information if the database supports cte with recursive
public
cte_support() : bool
Return values
bool —true or false
custom_order()
Function which constructs an optimize custom order string as an improved alternative to find_in_set()
public
custom_order(string $field, array<string|int, mixed> $array_values[, bool $desc = false ]) : string
Parameters
- $field : string
-
name
- $array_values : array<string|int, mixed>
-
Field values sequenced in array via order priority. Must cast to int.
- $desc : bool = false
-
default false
Return values
string —case field when ... then ... end
data_seek()
Adjusts the result pointer to an arbitrary row in a query result.
public
data_seek(object $result, int $offset) : bool
Parameters
- $result : object
- $offset : int
-
The row offset.
Return values
bool —True on success, or false on failure.
drop_table()
Drop a table.
public
drop_table(string $table_name[, array<string|int, mixed> $parameters = [] ][, string $error = 'fatal' ]) : bool
Parameters
- $table_name : string
-
The name of the table to drop
- $parameters : array<string|int, mixed> = []
-
Not used at the moment
- $error : string = 'fatal'
Return values
bool —Whether or not the operation was successful
error()
Get the last error message string.
public
error([object|null $connection = null ]) : string
Parameters
- $connection : object|null = null
-
The connection to use (if null, $db_connection is used)
Return values
string —The last error message.
error_insert()
Save errors in the database safely.
public
error_insert(array<string|int, mixed> $error_array) : void
Parameters
- $error_array : array<string|int, mixed>
escape_string()
Escapes special characters in a string for use in an SQL statement, taking into account the current character set of the connection.
public
escape_string(string $string[, object|null $connection = null ]) : string
Parameters
- $string : string
- $connection : object|null = null
-
= null The connection to use (null to use $db_connection).
Return values
string —The escaped string.
escape_wildcard_string()
Escape the LIKE wildcards so that they match the character and not the wildcard.
public
escape_wildcard_string(string $string[, bool $translate_human_wildcards = false ]) : string
Parameters
- $string : string
-
The string to escape
- $translate_human_wildcards : bool = false
-
If true, turns human readable wildcards into SQL wildcards.
Return values
string —The escaped string
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- At the END of the class's file, call its exportStatic() method.
Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.
Regarding the $backcompat items:
A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names'].
$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.
Adding non-static properties to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.
fetch_all()
Fetches all rows from a result as an array.
public
fetch_all(object $request) : array<string|int, mixed>
Parameters
- $request : object
-
A query result resource.
Return values
array<string|int, mixed> —An array that contains all rows (records) in the result resource.
fetch_assoc()
Fetch the next row of a result set as an associative array.
public
fetch_assoc(object $result) : array<string|int, mixed>
Parameters
- $result : object
Return values
array<string|int, mixed> —One row of data, with string keys.
fetch_object()
Fetches all rows from a result as an object.
public
fetch_object(object $result[, string $class = 'stdClass' ][, array<string|int, mixed> $args = [] ]) : object|false|null
Parameters
- $result : object
-
A query result resource.
- $class : string = 'stdClass'
-
The name of the class to instantiate, set the properties of and return. If not specified, a stdClass object is returned.
- $args : array<string|int, mixed> = []
-
An optional array of parameters to pass to the constructor for class objects.
Return values
object|false|null —Returns an object representing the fetched row, where each property represents the name of the result set's column, null if there are no more rows in the result set, or false on failure.
fetch_row()
Fetch the next row of a result set as an enumerated array.
public
fetch_row(object $result) : array<string|int, mixed>|false
Parameters
- $result : object
Return values
array<string|int, mixed>|false —One row of data, with numeric keys.
free_result()
Frees the memory and data associated with the query result.
public
free_result(object $result) : bool
Parameters
- $result : object
Return values
boolget_vendor()
Figures out if we are using MySQL, Percona or MariaDB
public
get_vendor() : string
Return values
string —The database engine we are using
get_version()
Get the version number.
public
get_version() : string
Return values
string —The version
getClass()
public
static getClass(string $db_type) : string
Parameters
- $db_type : string
Return values
stringinsert()
Inserts one or more rows of data into a database table and optionally returns the resulting IDs.
public
insert(string $method, string $table, array<string|int, mixed> $columns, array<string|int, mixed> $data, array<string|int, mixed> $keys[, int $returnmode = 0 ][, object|null $connection = null ]) : int|array<string|int, mixed>|null
Parameters
- $method : string
-
INSERT or REPLACE.
- $table : string
-
The table (only used for Postgres).
- $columns : array<string|int, mixed>
-
Array of the columns we're inserting the data into. Should contain 'column' => 'datatype' pairs.
- $data : array<string|int, mixed>
-
Rows of data to insert. Each element of $data must be an array of values corresponding to $columns.
- $keys : array<string|int, mixed>
-
The keys for the table. Must not empty in replace mode.
- $returnmode : int = 0
-
0 = nothing, 1 = last row ID, 2 = all row IDs. Default: 0.
- $connection : object|null = null
-
The connection to use. If null, $db_connection is used.
Return values
int|array<string|int, mixed>|null —Null if $returnmode is 0, the ID of the most recently inserted row if $returnmode is 1, or the IDS of all the inserted rows if $returnmode is 2.
insert_id()
Gets the ID of the most recently inserted row.
public
insert_id(string $table[, string|null $field = null ][, object|null $connection = null ]) : int
Parameters
- $table : string
-
The table (only used for Postgres)
- $field : string|null = null
-
= null The specific field (not used here)
- $connection : object|null = null
-
= null The connection (if null, $db_connection is used)
Return values
int —The ID of the most recently inserted row
is_resource()
Validates whether the resource is a valid mysqli instance.
public
is_resource(mixed $result) : bool
Parameters
- $result : mixed
-
The string to test
Return values
bool —True if it is, false otherwise
list_columns()
Return column information for a table.
public
list_columns(string $table_name[, bool $detail = false ][, array<string|int, mixed> $parameters = [] ]) : array<string|int, mixed>
Parameters
- $table_name : string
-
The name of the table to get column info for
- $detail : bool = false
-
Whether or not to return detailed info. If true, returns the column info. If false, just returns the column names.
- $parameters : array<string|int, mixed> = []
-
Not used?
Return values
array<string|int, mixed> —An array of column names or detailed column info, depending on $detail
list_indexes()
Get index information.
public
list_indexes(string $table_name[, bool $detail = false ][, array<string|int, mixed> $parameters = [] ]) : array<string|int, mixed>
Parameters
- $table_name : string
-
The name of the table to get indexes for
- $detail : bool = false
-
Whether or not to return detailed info.
- $parameters : array<string|int, mixed> = []
-
Not used?
Return values
array<string|int, mixed> —An array of index names or a detailed array of index info, depending on $detail
list_tables()
This function lists all tables in the database.
public
list_tables([string|bool $db = false ][, string|bool $filter = false ]) : array<string|int, mixed>
Parameters
- $db : string|bool = false
-
string The database name or false to use the current DB
- $filter : string|bool = false
-
String to filter by or false to list all tables
Return values
array<string|int, mixed> —An array of table names
load()
Static method used to instantiate the child class specified by Config::$db_type.
public
final static load([array<string|int, mixed> $options = [] ]) : object
If $options is empty, correct settings will be determined automatically.
Parameters
- $options : array<string|int, mixed> = []
-
An array of database options.
Return values
object —An instance of a child class of this class.
native_replace()
Function which return the information if the database supports native replace inserts
public
native_replace() : bool
Return values
bool —true or false
num_fields()
Gets the number of fields in a result set.
public
num_fields(object $result) : int
Parameters
- $result : object
Return values
int —The number of fields (columns) in the result.
num_rows()
Gets the number of rows in a result set.
public
num_rows(object $result) : int
Parameters
- $result : object
Return values
int —The number of rows in the result.
optimize_table()
This function optimizes a table.
public
optimize_table(string $table) : int
Parameters
- $table : string
-
The table to be optimized
Return values
int —How much space was gained
ping()
Pings a server connection, and tries to reconnect if necessary.
public
ping([object|null $connection = null ]) : bool
Parameters
- $connection : object|null = null
-
The connection object (if null, $db_connection is used)
Return values
bool —True on success, or false on failure.
query()
Performs a query. Takes care of errors too.
public
query(string $identifier, string $db_string[, array<string|int, mixed> $db_values = [] ][, object|null $connection = null ]) : object|bool
Parameters
- $identifier : string
-
An identifier. Only used in PostgreSQL.
- $db_string : string
-
The database string
- $db_values : array<string|int, mixed> = []
-
= array() The values to be inserted into the string
- $connection : object|null = null
-
= null The connection to use (null to use $db_connection)
Return values
object|bool —Returns a query result resource (for SELECT queries), true (for UPDATE queries) or false if the query failed.
quote()
Prepares a query string for execution, but does not perform the query.
public
quote(string $db_string, array<string|int, mixed> $db_values[, object|null $connection = null ]) : string
Parameters
- $db_string : string
-
The database string.
- $db_values : array<string|int, mixed>
-
An array of values to be injected into the string.
- $connection : object|null = null
-
= null The connection to use (null to use $db_connection).
Return values
string —The string with the values inserted.
remove_column()
Removes a column.
public
remove_column(string $table_name, string $column_name[, array<string|int, mixed> $parameters = [] ][, string $error = 'fatal' ]) : bool
Parameters
- $table_name : string
-
The name of the table to drop the column from
- $column_name : string
-
The name of the column to drop
- $parameters : array<string|int, mixed> = []
-
Not used?
- $error : string = 'fatal'
Return values
bool —Whether or not the operation was successful
remove_index()
Remove an index.
public
remove_index(string $table_name, string $index_name[, array<string|int, mixed> $parameters = [] ][, string $error = 'fatal' ]) : bool
Parameters
- $table_name : string
-
The name of the table to remove the index from
- $index_name : string
-
The name of the index to remove
- $parameters : array<string|int, mixed> = []
-
Not used?
- $error : string = 'fatal'
Return values
bool —Whether or not the operation was successful
search_language()
Return the language for the textsearch index
public
search_language() : string|null
Return values
string|null —The PostgreSQL search language, or null for MySQL.
search_query()
Returns the correct query for this search type.
public
search_query(string $identifier, string $db_string[, array<string|int, mixed> $db_values = [] ][, object|null $connection = null ]) : resource
Parameters
- $identifier : string
-
A query identifier
- $db_string : string
-
The query text
- $db_values : array<string|int, mixed> = []
-
An array of values to pass to $this->query()
- $connection : object|null = null
-
The current DB connection resource
Return values
resource —The query result resource from $this->query()
search_support()
This function will tell you whether this database type supports this search type.
public
search_support(string $search_type) : bool
Parameters
- $search_type : string
-
The search type.
Return values
bool —Whether or not the specified search type is supported by this db system
select()
Selects the default database for database queries.
public
select(string $database[, object|null $connection = null ]) : bool
Parameters
- $database : string
-
The database
- $connection : object|null = null
-
The connection object (if null, $db_connection is used)
Return values
bool —Whether the database was selected
server_info()
Gets information, such as the version, about the database server.
public
server_info([object|null $connection = null ]) : string
Parameters
- $connection : object|null = null
-
The connection to use (if null, $db_connection is used)
Return values
string —The server info.
table_sql()
Dumps the schema (CREATE) for a table.
public
table_sql(string $tableName) : string
Parameters
- $tableName : string
-
The name of the table
Return values
string —The "CREATE TABLE" SQL string for this table
table_structure()
Get table structure.
public
table_structure(string $table_name) : array<string|int, mixed>
Parameters
- $table_name : string
-
The name of the table
Return values
array<string|int, mixed> —An array of table structure - the name, the column info from and the index info from
transaction()
Do a transaction.
public
transaction([string $type = 'commit' ][, object|null $connection = null ]) : bool
Parameters
- $type : string = 'commit'
-
The step to perform (i.e. 'begin', 'commit', 'rollback')
- $connection : object|null = null
-
The connection to use (if null, $db_connection is used)
Return values
bool —True if successful, false otherwise
unescape_string()
Reverses the escape_string function.
public
unescape_string(string $string) : string
Parameters
- $string : string
Return values
string —The unescaped string.
update_from()
Updates data in a table, using data from other tables.
public
update_from(array<string|int, mixed> $table, array<string|int, mixed> $from_tables, string $set, string $where, array<string|int, mixed> $db_values[, object|null $connection = null ]) : bool
Parameters
- $table : array<string|int, mixed>
-
Info about the table to be updated. Example: ['name' => '{db_prefix}foo', 'alias' => 'f']
- $from_tables : array<string|int, mixed>
-
Info about the tables to get data from. Example: [ [ 'name' => '{db_prefix}bar', 'alias' => 'b', 'condition' => 'f.baz = b.qux', ] ]
- $set : string
-
A string containing the SET instructions for the update query.
- $where : string
-
A string containing any WHERE conditions for the update query.
- $db_values : array<string|int, mixed>
-
The values to be inserted into the compiled query string.
- $connection : object|null = null
-
The connection to use (if null, $db_connection will be used).
Return values
bool —True if the update was successful, otherwise false.
__construct()
Constructor.
protected
__construct([array<string|int, mixed> $options = [] ]) : mixed
If $options is empty, correct settings will be determined automatically.
Parameters
- $options : array<string|int, mixed> = []
-
An array of database options.
create_query_column()
Creates a query for a column
protected
create_query_column(array<string|int, mixed> $column) : string
Parameters
- $column : array<string|int, mixed>
-
An array of column info
Return values
string —The column definition
error_backtrace()
This function tries to work out additional error information from a back trace.
protected
error_backtrace(string $error_message[, string $log_message = '' ][, string|int|bool $error_type = false ][, string $file = null ][, int $line = null ]) : void|array<string|int, mixed>
Parameters
- $error_message : string
-
The error message
- $log_message : string = ''
-
The message to log
- $error_type : string|int|bool = false
-
What type of error this is
- $file : string = null
-
The file the error occurred in
- $line : int = null
-
What line of $file the code which generated the error is on
Return values
void|array<string|int, mixed> —Returns an array with the file and line if $error_type is 'return'
initiate()
Initiates a connection to a database.
protected
initiate(string $user, string $passwd[, array<string|int, mixed> $options = [] ]) : void
Resulting connection is stored as $this->connection.
Parameters
- $user : string
-
The database username
- $passwd : string
-
The database password
- $options : array<string|int, mixed> = []
-
An array of database options
mapToSmcFunc()
For backward compatibility, make various public methods available as Utils::$smcFunc functions.
protected
mapToSmcFunc() : void
prefixReservedTables()
Appends the correct prefix to the reserved tables' names.
protected
prefixReservedTables() : void
replacement__callback()
Callback for preg_replace_callback on the query.
protected
replacement__callback(array<string|int, mixed> $matches) : string
It replaces on the fly a few pre-defined strings ('query_see_board', 'query_wanna_see_board', etc.) with their current values from User::$me.
In addition, it performs checks and sanitization on the values sent to the database.
Parameters
- $matches : array<string|int, mixed>
-
The matches from preg_replace_callback
Return values
string —The appropriate string depending on $matches[1]