DatabaseApi
in package
uses
BackwardCompatibility
Class DatabaseApi
Table of Contents
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
- $reservedTables : array<string|int, mixed>
- $backcompat : array<string|int, mixed>
Methods
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- getClass() : string
- load() : object
- Static method used to instantiate the child class specified by Config::$db_type.
- __construct() : mixed
- Protected constructor to prevent multiple instances.
- 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.
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
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
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
Whether the database supports PCRE regular expressions. Always true for PostgreSQL. Depends on version for MySQL.
$sybase
public
bool
$sybase
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
Value of the appropriate *_TITLE constant.
$unbuffered
public
static bool
$unbuffered
= false
Force unbuffered output. Only applicable to MySQL.
$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!
$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
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.
getClass()
public
static getClass(string $db_type) : string
Parameters
- $db_type : string
Return values
stringload()
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.
__construct()
Protected constructor to prevent multiple instances.
protected
__construct() : mixed
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