4 # Backwards compatibility wrapper for Database.php
6 # I imagine this file will eventually become a backwards
7 # compatibility wrapper around a load balancer object, and
8 # the load balancer will finally call Database, which will
9 # represent a single connection
11 # NB: This file follows a connect on demand scheme. Do
12 # not access the $wgDatabase variable directly unless
13 # you intend to set it. Use wfGetDB().
18 if ($wgDBtype=="mysql") {
19 require_once( "Database.php" );
21 } elseif ($wgDBtype=="pgsql") {
22 require_once( "DatabasePostgreSQL.php" );
27 # $db: DB_READ = -1 read from slave (or only server)
28 # DB_WRITE = -2 write to master (or only server)
29 # 0,1,2,... query a database with a specific index
30 # Replication is not actually implemented just yet
31 # Usually aborts on failure
32 # If errors are explicitly ignored, returns success
33 function wfQuery( $sql, $db, $fname = "" )
35 global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname,
36 $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
38 if ( !is_numeric( $db ) ) {
39 # Someone has tried to call this the old way
40 $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) );
44 return $db->query( $sql, $fname );
50 global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname,
51 $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
53 $wgDatabase = Database
::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword,
54 $wgDBname, false, $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors );
59 # Turns buffering of SQL result sets on (true) or off (false). Default is
60 # "on" and it should not be changed without good reasons.
61 # Returns the previous state.
63 function wfBufferSQLResults( $newstate )
66 return $db->setBufferResults( $newstate );
69 # Turns on (false) or off (true) the automatic generation and sending
70 # of a "we're sorry, but there has been a database error" page on
71 # database errors. Default is on (false). When turned off, the
72 # code should use wfLastErrno() and wfLastError() to handle the
73 # situation as appropriate.
74 # Returns the previous state.
76 function wfIgnoreSQLErrors( $newstate )
79 return $db->setIgnoreErrors( $newstate );
82 function wfFreeResult( $res )
85 $db->freeResult( $res );
88 function wfFetchObject( $res )
91 return $db->fetchObject( $res );
94 function wfFetchRow( $res )
97 return $db->fetchRow ( $res );
100 function wfNumRows( $res )
103 return $db->numRows( $res );
106 function wfNumFields( $res )
109 return $db->numFields( $res );
112 function wfFieldName( $res, $n )
115 return $db->fieldName( $res, $n );
118 function wfInsertId()
121 return $db->insertId();
123 function wfDataSeek( $res, $row )
126 return $db->dataSeek( $res, $row );
129 function wfLastErrno()
132 return $db->lastErrno();
135 function wfLastError()
138 return $db->lastError();
141 function wfAffectedRows()
144 return $db->affectedRows();
147 function wfLastDBquery()
150 return $db->lastQuery();
153 function wfSetSQL( $table, $var, $value, $cond )
156 return $db->set( $table, $var, $value, $cond );
159 function wfGetSQL( $table, $var, $cond="" )
162 return $db->get( $table, $var, $cond );
165 function wfFieldExists( $table, $field )
168 return $db->fieldExists( $table, $field );
171 function wfIndexExists( $table, $index )
174 return $db->indexExists( $table, $index );
177 function wfInsertArray( $table, $array )
180 return $db->insertArray( $table, $array );
183 function wfGetArray( $table, $vars, $conds, $fname = "wfGetArray" )
186 return $db->getArray( $table, $vars, $conds, $fname );
189 function wfUpdateArray( $table, $values, $conds, $fname = "wfUpdateArray" )
192 $db->updateArray( $table, $values, $conds, $fname );