* added file description header
[mediawiki.git] / includes / db / DatabaseType.php
blobd0154241c506d9ecd3d7210bd631d16292410c0e
1 <?php
2 /**
3 * Base interface for all DBMS-specific code.
5 * @file
6 * @ingroup Database
7 */
9 /**
10 * Base interface for all DBMS-specific code. At a bare minimum, all of the
11 * following must be implemented to support MediaWiki
13 * @ingroup Database
15 interface DatabaseType {
17 /**
18 * Get the type of the DBMS, as it appears in $wgDBtype.
20 * @return string
22 public function getType();
24 /**
25 * Open a connection to the database. Usually aborts on failure
26 * If the failFunction is set to a non-zero integer, returns success
28 * @param $server String: database server host
29 * @param $user String: database user name
30 * @param $password String: database user password
31 * @param $dbName String: database name
32 * @return bool
33 * @throws DBConnectionError
35 public function open( $server, $user, $password, $dbName );
37 /**
38 * The DBMS-dependent part of query()
39 * @todo @fixme Make this private someday
41 * @param $sql String: SQL query.
42 * @return Result object to feed to fetchObject, fetchRow, ...; or false on failure
43 * @private
45 /*private*/ function doQuery( $sql );
47 /**
48 * Fetch the next row from the given result object, in object form.
49 * Fields can be retrieved with $row->fieldname, with fields acting like
50 * member variables.
52 * @param $res SQL result object as returned from DatabaseBase::query(), etc.
53 * @return Row object
54 * @throws DBUnexpectedError Thrown if the database returns an error
56 public function fetchObject( $res );
58 /**
59 * Fetch the next row from the given result object, in associative array
60 * form. Fields are retrieved with $row['fieldname'].
62 * @param $res SQL result object as returned from DatabaseBase::query(), etc.
63 * @return Row object
64 * @throws DBUnexpectedError Thrown if the database returns an error
66 public function fetchRow( $res );
68 /**
69 * Get the number of rows in a result object
71 * @param $res Mixed: A SQL result
72 * @return int
74 public function numRows( $res );
76 /**
77 * Get the number of fields in a result object
78 * @see http://www.php.net/mysql_num_fields
80 * @param $res Mixed: A SQL result
81 * @return int
83 public function numFields( $res );
85 /**
86 * Get a field name in a result object
87 * @see http://www.php.net/mysql_field_name
89 * @param $res Mixed: A SQL result
90 * @param $n Integer
91 * @return string
93 public function fieldName( $res, $n );
95 /**
96 * Get the inserted value of an auto-increment row
98 * The value inserted should be fetched from nextSequenceValue()
100 * Example:
101 * $id = $dbw->nextSequenceValue('page_page_id_seq');
102 * $dbw->insert('page',array('page_id' => $id));
103 * $id = $dbw->insertId();
105 * @return int
107 public function insertId();
110 * Change the position of the cursor in a result object
111 * @see http://www.php.net/mysql_data_seek
113 * @param $res Mixed: A SQL result
114 * @param $row Mixed: Either MySQL row or ResultWrapper
116 public function dataSeek( $res, $row );
119 * Get the last error number
120 * @see http://www.php.net/mysql_errno
122 * @return int
124 public function lastErrno();
127 * Get a description of the last error
128 * @see http://www.php.net/mysql_error
130 * @return string
132 public function lastError();
135 * mysql_fetch_field() wrapper
136 * Returns false if the field doesn't exist
138 * @param $table string: table name
139 * @param $field string: field name
141 public function fieldInfo( $table, $field );
144 * Get the number of rows affected by the last write query
145 * @see http://www.php.net/mysql_affected_rows
147 * @return int
149 public function affectedRows();
152 * Wrapper for addslashes()
154 * @param $s string: to be slashed.
155 * @return string: slashed string.
157 public function strencode( $s );
160 * Returns a wikitext link to the DB's website, e.g.,
161 * return "[http://www.mysql.com/ MySQL]";
162 * Should at least contain plain text, if for some reason
163 * your database has no website.
165 * @return string: wikitext of a link to the server software's web site
167 public static function getSoftwareLink();
170 * A string describing the current software version, like from
171 * mysql_get_server_info(). Will be listed on Special:Version, etc.
173 * @return string: Version information from the database
175 public function getServerVersion();