Skip to content
Spuds edited this page Jan 26, 2023 · 2 revisions

DEVELOPER DOCUMENTATION > DATABASE LAYER

Object oriented database layer

ElkArte implements an object oriented database layer, supporting multiple database systems.

Changes from SMF:

Functions previously available in $smcFunc[] array have been redesigned as methods of the database classes, to make them easier to use, improve, and implement for other database systems.

Functions from core database layer -> Database object, corresponding methods.

  • to retrieve a Database object, call database() function: $db = database();
  • example:
    $smcFunc['db_query']($params);
    // becomes
    $db = database();
    $db->query($params);
  • The object oriented version has the same list of parameters as the function had, in its $smcFunc version. Therefore it's a straightforward switch to it, for both core and addons/externals. Just replace the $smcFunc array itself with $db->function_name().
  • Under the hood, the Database object is created for your respective system.
  • Database is an interface, which Database_MySQL (respectively Database_PostgreSQL, Database_SQLite) implement.

Functions from 'search' extension -> DBSearch object, corresponding methods.

  • to retrieve a DbSearch object, call db_search() function: $db_search = db_search();
  • example:
    $smcFunc['db_search_query']($params);
    // becomes
    $db_search = db_search();
    $db_search->search_query($params);
  • You no longer need to call db_extend('search'), only directly db_search().
  • 'support_ignore' has moved to Database object. So you'll find it as $db->support_ignore(), where $db is returned by database().
  • The object oriented version has the same list of parameters and behavior.
  • Under the hood, the DbSearch object is created for your respective system.
  • DbSearch is an interface, which DbSearch_MySQL (respectively DbSearch_PostgreSQL, DbSearch_SQLite) implement.

Functions from 'packages' extension -> DbTable object, corresponding methods.

  • To retrieve a DbTable object, call db_table() function: $db_table = db_table();
  • example:
    $smcFunc['db_list_columns']($params);
    // becomes
    $db_table = db_table();
    $db_table->db_list_columns($params);
  • You no longer need to call db_extend('packages'), only directly db_table().
  • The object oriented version has the same list of parameters and behavior.
  • Under the hood, the DbTable object is created for your respective system.
  • DbTable is an interface, which DbTable_MySQL (respectively DbTable_PostgreSQL, DbTable_SQLite) implement.

Functions from 'extra' extension -> moved to Database object, corresponding methods.

  • example:
    $smcFunc['db_backup_table']($params);
    // becomes
    $db = database();
    $db->db_backup_table($params);
  • There is no longer any need to call db_extend('extra') or db_extend(), they are directly available.

Functions for string manipulation -> Util class, corresponding static methods.

  • example:
    $smcFunc['htmltrim']($params);
    // becomes
    Util::htmltrim($params);

Notes on internal implementation

The database is initialized by a call to elk_db_initiate(). Name kept for easy reference. This will at its turn use the initiate() static method of the appropriate Database class, to create and initialize an instance and get a connection.

HOME > TECH GUIDES

Architecture

Functions and Variables

  • About $user_info variable
  • About the createList() function.
  • About [Template Layers](Template layers).
  • About [is_activated](is activated) values.

Customization

  • [Create a theme](Make a new theme)
  • [Create an Addon](Create an Addon)

GitHub

Clone this wiki locally