Manual:Database.php

From MediaWiki.org
Jump to: navigation, search
Translate this page; This page contains changes which are not marked for translation.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎日本語 • ‎polski • ‎português • ‎português do Brasil

Description[edit]

Database.php contains the Database class (formerly DatabaseBase) that serves as a base for all database classes (MySQL, PostgreSQL, etc).

Functions[edit]

These are invoked using the database abstraction layer accessed via wfGetDB(), e.g. $dbw->affectedRows().

Name Description
affectedRows () Get the number of rows affected by the last write query.
dataSeek ($res, $row) Change the position of the cursor in a result object.
fetchObject ($res) Fetch the next row from the given result object, in object form.
fetchRow ($res) Fetch the next row from the given result object, in associative array form.
fieldInfo ($table, $field) Returns false if the field doesn't exist.
fieldName ($res, $n) Get a field name in a result object.
getServerInfo () A string describing the current software version, and possibly other details in a user-friendly way.
getServerVersion () A string describing the current software version, like from mysql_get_server_info().
getSoftwareLink () Returns a wikitext link to the DB's website, e.g., return "MySQL"; Should at least contain plain text, if for some reason your database has no website.
getType () Get the type of the DBMS, as it appears in $wgDBtype.
indexInfo ($table, $index, $fname=__METHOD__) Get information about an index into an object.
insertId () Get the inserted value of an auto-increment row.
lastErrno () Get the last error number.
lastError () Get a description of the last error.
numFields ($res) Get the number of fields in a result object.
numRows ($res) Get the number of rows in a result object.
open ($server, $user, $password, $dbName) Open a connection to the database.
strencode ($s) Wrapper for addslashes().

Timestamp functions[edit]

Name Description
timestamp ( $ts = 0 ) Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting into timestamp fields in this DBMS. The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.
timestampOrNull ( $ts = null ) Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting into timestamp fields in this DBMS. If NULL is input, it is passed through, allowing NULL values to be inserted into timestamp fields. The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.

See also[edit]

DatabasesManual:Database layout Engines: MySQL/MariaDBManual:MySQLOracleManual:OraclePostgreSQLManual:PostgreSQLSQLiteManual:SQLiteSQL ServerManual:Microsoft SQL Server

Technical documentation: SchemaManual:Database layout (tablesCategory:MediaWiki database tables) – API property associationsAPI:Database field and API property associationsField prefixesDatabase field prefixesPrimary key storage in other fieldsManual:Primary key storage in other fieldsWikimedia extension tablesCategory:Wikimedia extension database tables
Configuration: SettingsManual:Configuration_settings#Database_settingsSharingManual:Shared database
Development: AccessManual:Database accessOptimizationDatabase optimizationPolicyDevelopment policy#Database_patchesUpdaterManual:DatabaseUpdater.phpExtension schema updatesManual:Hooks/LoadExtensionSchemaUpdatesPatch fileManual:SQL patch file

Core tables: archivebot_passwordscategorycategorylinkschange_tagcommentconfigexternallinksfilearchivehitcounterimageimagelinksimage_comment_tempinterwikiiwlinksipblocksip_changesjobl10n_cachelanglinkslogginglog_searchmsg_resourcemsg_resource_linksmodule_depsobjectcacheoldimagepagepagelinkspage_propspage_restrictionsprotected_titlesquerycachequerycachetwoquerycache_inforecentchangesredirectrevisionrevision_comment_tempsearchindexsitessite_identifiers - site_statstag_summarytemplatelinkstexttranscacheupdateloguploadstashuseruser_former_groupsuser_groupsuser_newtalkuser_propertiestag_summaryvalid_tagwatchlist