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 # Note: $wgDatabase has ceased to exist. Destroy all references.
16 if ($wgDBtype=="mysql") {
17 require_once( "Database.php" );
19 } elseif ($wgDBtype=="pgsql") {
20 require_once( "DatabasePostgreSQL.php" );
25 # Usually aborts on failure
26 # If errors are explicitly ignored, returns success
27 function wfQuery( $sql, $db, $fname = "" )
30 if ( !is_numeric( $db ) ) {
31 # Someone has tried to call this the old way
32 $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) );
36 return $c->query( $sql, $fname );
42 function wfSingleQuery( $sql, $db, $fname = "" )
44 $res = wfQuery($sql, $db, $fname );
45 $row = wfFetchRow( $res );
51 function &wfGetDB( $db = DB_LAST
)
53 global $wgLoadBalancer;
54 return $wgLoadBalancer->getConnection( $db );
57 # Turns buffering of SQL result sets on (true) or off (false). Default is
58 # "on" and it should not be changed without good reasons.
59 # Returns the previous state.
61 function wfBufferSQLResults( $newstate, $dbi = DB_LAST
)
63 $db =& wfGetDB( $dbi );
64 if ( $db !== false ) {
65 return $db->setBufferResults( $newstate );
71 # Turns on (false) or off (true) the automatic generation and sending
72 # of a "we're sorry, but there has been a database error" page on
73 # database errors. Default is on (false). When turned off, the
74 # code should use wfLastErrno() and wfLastError() to handle the
75 # situation as appropriate.
76 # Returns the previous state.
78 function wfIgnoreSQLErrors( $newstate, $dbi = DB_LAST
)
80 $db =& wfGetDB( $dbi );
81 if ( $db !== false ) {
82 return $db->setIgnoreErrors( $newstate );
88 function wfFreeResult( $res, $dbi = DB_LAST
)
90 $db =& wfGetDB( $dbi );
91 if ( $db !== false ) {
92 $db->freeResult( $res );
99 function wfFetchObject( $res, $dbi = DB_LAST
)
101 $db =& wfGetDB( $dbi );
102 if ( $db !== false ) {
103 return $db->fetchObject( $res, $dbi = DB_LAST
);
109 function wfFetchRow( $res, $dbi = DB_LAST
)
111 $db =& wfGetDB( $dbi );
112 if ( $db !== false ) {
113 return $db->fetchRow ( $res, $dbi = DB_LAST
);
119 function wfNumRows( $res, $dbi = DB_LAST
)
121 $db =& wfGetDB( $dbi );
122 if ( $db !== false ) {
123 return $db->numRows( $res, $dbi = DB_LAST
);
129 function wfNumFields( $res, $dbi = DB_LAST
)
131 $db =& wfGetDB( $dbi );
132 if ( $db !== false ) {
133 return $db->numFields( $res );
139 function wfFieldName( $res, $n, $dbi = DB_LAST
)
141 $db =& wfGetDB( $dbi );
142 if ( $db !== false ) {
143 return $db->fieldName( $res, $n, $dbi = DB_LAST
);
149 function wfInsertId( $dbi = DB_LAST
)
151 $db =& wfGetDB( $dbi );
152 if ( $db !== false ) {
153 return $db->insertId();
159 function wfDataSeek( $res, $row, $dbi = DB_LAST
)
161 $db =& wfGetDB( $dbi );
162 if ( $db !== false ) {
163 return $db->dataSeek( $res, $row );
169 function wfLastErrno( $dbi = DB_LAST
)
171 $db =& wfGetDB( $dbi );
172 if ( $db !== false ) {
173 return $db->lastErrno();
179 function wfLastError( $dbi = DB_LAST
)
181 $db =& wfGetDB( $dbi );
182 if ( $db !== false ) {
183 return $db->lastError();
189 function wfAffectedRows( $dbi = DB_LAST
)
191 $db =& wfGetDB( $dbi );
192 if ( $db !== false ) {
193 return $db->affectedRows();
199 function wfLastDBquery( $dbi = DB_LAST
)
201 $db =& wfGetDB( $dbi );
202 if ( $db !== false ) {
203 return $db->lastQuery();
209 function wfSetSQL( $table, $var, $value, $cond, $dbi = DB_WRITE
)
211 $db =& wfGetDB( $dbi );
212 if ( $db !== false ) {
213 return $db->set( $table, $var, $value, $cond );
219 function wfGetSQL( $table, $var, $cond="", $dbi = DB_LAST
)
221 $db =& wfGetDB( $dbi );
222 if ( $db !== false ) {
223 return $db->get( $table, $var, $cond );
229 function wfFieldExists( $table, $field, $dbi = DB_LAST
)
231 $db =& wfGetDB( $dbi );
232 if ( $db !== false ) {
233 return $db->fieldExists( $table, $field );
239 function wfIndexExists( $table, $index, $dbi = DB_LAST
)
241 $db =& wfGetDB( $dbi );
242 if ( $db !== false ) {
243 return $db->indexExists( $table, $index );
249 function wfInsertArray( $table, $array, $fname = "wfInsertArray", $dbi = DB_WRITE
)
251 $db =& wfGetDB( $dbi );
252 if ( $db !== false ) {
253 return $db->insertArray( $table, $array, $fname );
259 function wfGetArray( $table, $vars, $conds, $fname = "wfGetArray", $dbi = DB_LAST
)
261 $db =& wfGetDB( $dbi );
262 if ( $db !== false ) {
263 return $db->getArray( $table, $vars, $conds, $fname );
269 function wfUpdateArray( $table, $values, $conds, $fname = "wfUpdateArray", $dbi = DB_WRITE
)
271 $db =& wfGetDB( $dbi );
272 if ( $db !== false ) {
273 $db->updateArray( $table, $values, $conds, $fname );