3 * Legacy database functions, for compatibility with pre-1.3 code
4 * NOTE: this file is no longer loaded by default.
9 * Usually aborts on failure
10 * If errors are explicitly ignored, returns success
11 * @param $sql String: SQL query
12 * @param $db Mixed: database handler
13 * @param $fname String: name of the php function calling
15 function wfQuery( $sql, $db, $fname = '' ) {
16 if ( !is_numeric( $db ) ) {
17 # Someone has tried to call this the old way
18 throw new FatalError( wfMsgNoDB( 'wrong_wfQuery_params', $db, $sql ) );
22 return $c->query( $sql, $fname );
30 * @param $sql String: SQL query
32 * @param $fname String: name of the php function calling
33 * @return Array: first row from the database
35 function wfSingleQuery( $sql, $dbi, $fname = '' ) {
36 $db = wfGetDB( $dbi );
37 $res = $db->query($sql, $fname );
38 $row = $db->fetchRow( $res );
40 $db->freeResult( $res );
45 * Turns on (false) or off (true) the automatic generation and sending
46 * of a "we're sorry, but there has been a database error" page on
47 * database errors. Default is on (false). When turned off, the
48 * code should use wfLastErrno() and wfLastError() to handle the
49 * situation as appropriate.
53 * @return Returns the previous state.
55 function wfIgnoreSQLErrors( $newstate, $dbi = DB_LAST
) {
56 $db = wfGetDB( $dbi );
57 if ( $db !== false ) {
58 return $db->ignoreErrors( $newstate );
65 * @param $res Database result handler
70 * Free a database result
71 * @return Bool: whether result is sucessful or not.
73 function wfFreeResult( $res, $dbi = DB_LAST
)
75 $db = wfGetDB( $dbi );
76 if ( $db !== false ) {
77 $db->freeResult( $res );
85 * Get an object from a database result
86 * @return object|false object we requested
88 function wfFetchObject( $res, $dbi = DB_LAST
) {
89 $db = wfGetDB( $dbi );
90 if ( $db !== false ) {
91 return $db->fetchObject( $res, $dbi = DB_LAST
);
98 * Get a row from a database result
99 * @return object|false row we requested
101 function wfFetchRow( $res, $dbi = DB_LAST
) {
102 $db = wfGetDB( $dbi );
103 if ( $db !== false ) {
104 return $db->fetchRow ( $res, $dbi = DB_LAST
);
111 * Get a number of rows from a database result
112 * @return integer|false number of rows
114 function wfNumRows( $res, $dbi = DB_LAST
) {
115 $db = wfGetDB( $dbi );
116 if ( $db !== false ) {
117 return $db->numRows( $res, $dbi = DB_LAST
);
124 * Get the number of fields from a database result
125 * @return integer|false number of fields
127 function wfNumFields( $res, $dbi = DB_LAST
) {
128 $db = wfGetDB( $dbi );
129 if ( $db !== false ) {
130 return $db->numFields( $res );
137 * Return name of a field in a result
138 * @param $res Mixed: Ressource link see Database::fieldName()
139 * @param $n Integer: id of the field
140 * @param $dbi Default DB_LAST
141 * @return string|false name of field
143 function wfFieldName( $res, $n, $dbi = DB_LAST
)
145 $db = wfGetDB( $dbi );
146 if ( $db !== false ) {
147 return $db->fieldName( $res, $n, $dbi = DB_LAST
);
155 * @todo document function
157 function wfInsertId( $dbi = DB_LAST
) {
158 $db = wfGetDB( $dbi );
159 if ( $db !== false ) {
160 return $db->insertId();
167 * @todo document function
169 function wfDataSeek( $res, $row, $dbi = DB_LAST
) {
170 $db = wfGetDB( $dbi );
171 if ( $db !== false ) {
172 return $db->dataSeek( $res, $row );
179 * @todo document function
181 function wfLastErrno( $dbi = DB_LAST
) {
182 $db = wfGetDB( $dbi );
183 if ( $db !== false ) {
184 return $db->lastErrno();
191 * @todo document function
193 function wfLastError( $dbi = DB_LAST
) {
194 $db = wfGetDB( $dbi );
195 if ( $db !== false ) {
196 return $db->lastError();
203 * @todo document function
205 function wfAffectedRows( $dbi = DB_LAST
) {
206 $db = wfGetDB( $dbi );
207 if ( $db !== false ) {
208 return $db->affectedRows();
215 * @todo document function
217 function wfLastDBquery( $dbi = DB_LAST
) {
218 $db = wfGetDB( $dbi );
219 if ( $db !== false ) {
220 return $db->lastQuery();
227 * @see Database::Set()
228 * @todo document function
233 * @param $dbi Default DB_MASTER
235 function wfSetSQL( $table, $var, $value, $cond, $dbi = DB_MASTER
)
237 $db = wfGetDB( $dbi );
238 if ( $db !== false ) {
239 return $db->set( $table, $var, $value, $cond );
247 * @see Database::selectField()
248 * @todo document function
251 * @param $cond Default ''
252 * @param $dbi Default DB_LAST
254 function wfGetSQL( $table, $var, $cond='', $dbi = DB_LAST
)
256 $db = wfGetDB( $dbi );
257 if ( $db !== false ) {
258 return $db->selectField( $table, $var, $cond );
265 * @see Database::fieldExists()
266 * @todo document function
269 * @param $dbi Default DB_LAST
270 * @return Result of Database::fieldExists() or false.
272 function wfFieldExists( $table, $field, $dbi = DB_LAST
) {
273 $db = wfGetDB( $dbi );
274 if ( $db !== false ) {
275 return $db->fieldExists( $table, $field );
282 * @see Database::indexExists()
283 * @todo document function
284 * @param $table String
286 * @param $dbi Default DB_LAST
287 * @return Result of Database::indexExists() or false.
289 function wfIndexExists( $table, $index, $dbi = DB_LAST
) {
290 $db = wfGetDB( $dbi );
291 if ( $db !== false ) {
292 return $db->indexExists( $table, $index );
299 * @see Database::insert()
300 * @todo document function
301 * @param $table String
302 * @param $array Array
303 * @param $fname String, default 'wfInsertArray'.
304 * @param $dbi Default DB_MASTER
305 * @return result of Database::insert() or false.
307 function wfInsertArray( $table, $array, $fname = 'wfInsertArray', $dbi = DB_MASTER
) {
308 $db = wfGetDB( $dbi );
309 if ( $db !== false ) {
310 return $db->insert( $table, $array, $fname );
317 * @see Database::getArray()
318 * @todo document function
319 * @param $table String
322 * @param $fname String, default 'wfGetArray'.
323 * @param $dbi Default DB_LAST
324 * @return result of Database::getArray() or false.
326 function wfGetArray( $table, $vars, $conds, $fname = 'wfGetArray', $dbi = DB_LAST
) {
327 $db = wfGetDB( $dbi );
328 if ( $db !== false ) {
329 return $db->getArray( $table, $vars, $conds, $fname );
336 * @see Database::update()
337 * @param $table String
340 * @param $fname String, default 'wfUpdateArray'
341 * @param $dbi Default DB_MASTER
342 * @return Result of Database::update()) or false;
343 * @todo document function
345 function wfUpdateArray( $table, $values, $conds, $fname = 'wfUpdateArray', $dbi = DB_MASTER
) {
346 $db = wfGetDB( $dbi );
347 if ( $db !== false ) {
348 $db->update( $table, $values, $conds, $fname );
356 * @todo document function
358 function wfTableName( $name, $dbi = DB_LAST
) {
359 $db = wfGetDB( $dbi );
360 if ( $db !== false ) {
361 return $db->tableName( $name );
368 * @todo document function
370 function wfStrencode( $s, $dbi = DB_LAST
) {
371 $db = wfGetDB( $dbi );
372 if ( $db !== false ) {
373 return $db->strencode( $s );
380 * @todo document function
382 function wfNextSequenceValue( $seqName, $dbi = DB_MASTER
) {
383 $db = wfGetDB( $dbi );
384 if ( $db !== false ) {
385 return $db->nextSequenceValue( $seqName );
392 * @todo document function
394 function wfUseIndexClause( $index, $dbi = DB_SLAVE
) {
395 $db = wfGetDB( $dbi );
396 if ( $db !== false ) {
397 return $db->useIndexClause( $index );