Jump to content

Manual:Database.php

From mediawiki.org
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This page is a translated version of the page Manual:Database.php and the translation is 100% complete.

描述

Database.php包含Database类(以前称为DatabaseBase),该类用作所有数据库类(MySQL的基础, PostgreSQL等)。

通常開發人員不會直接呼叫此類別,而是透過 資料庫抽象層 來進行操作。

實作

函数

下列表格僅列出部份已實作的功能:

名称 描述
affectedRows () 获取上一次写查询影响的行数。
dataSeek ($res, $row) 更改光标在结果对象中的位置。
fieldInfo ($table, $field) 如果该字段不存在,则返回false
fieldName ($res, $n) 获取结果对象中的字段名称。
getServerInfo () 一个字符串描述当前软件版本,并可能以方用户友好的方式描述其他详细信息。
getServerVersion () 描述当前软件版本的字符串,例如mysql_get_server_info()中的字符串。
getSoftwareLink () 返回指向数据库网站的维基文字链接,例如,返回“MySQL”; 如果您的数据库没有网站,则至少应包含纯文本。
getType () 获取DBMS的类型,如$wgDBtype中所示。
indexInfo ($table, $index, $fname=__METHOD__) 获取有关对象索引的信息。
insertId () 获取自动增量行的插入值。
lastErrno () 获取最后的错误号。
lastError () 获取最后一个错误的描述。
numFields ($res) 获取结果对象中的字段数。
open ($server, $user, $password, $dbName) 打开与数据库的连接。
strencode ($s) 包装addslashes()
tableExists ($table) 如果$table不存在,则返回false
fieldExists( ... )

indexExists( ... )

Other boolean methods for running checks.

Methods for building SQL queries

newSelectQueryBuilder() Get a new instance of SelectQueryBuilder bound to the present connection. Overridden by DBConnRef .
select( $table, $vars, $conds = '', $fname = __METHOD__, $options = [], $join_conds = [] ) Prepare a SELECT statement.
selectField( $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = [] )
selectFieldValues( $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = [] )
selectRow( $options = [], $join_conds = [] $table, $vars, $conds, $fname = __METHOD__, )
estimateRowCount( ... )

selectRowCount( ... )

lockForUpdate( ... ) Locks rows returned by SELECT query


时间戳函数

timestamp ( $ts = 0 ) wfTimestamp() 接受的格式之一的时间戳转换为用于插入此DBMS中的timestamp字段的格式。 结果未加引号,需要先通过addQuotes()传递,然后才能将其包含在原始SQL中。
timestampOrNull ( $ts = null ) wfTimestamp() 接受的格式之一的时间戳转换为用于插入此DBMS中的timestamp字段的格式。 若輸入 NULL,則直接傳遞該值,允許將 NULL 值插入時間戳記的欄位。 结果未加引号,需要先通过addQuotes()传递,然后才能将其包含在原始SQL中。

Extended by

参阅