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().
19 if ($wgDBtype=="mysql") {
20 require_once( "Database.php" );
22 } elseif ($wgDBtype=="pgsql") {
23 require_once( "DatabasePostgreSQL.php" );
28 # Replication is not actually implemented just yet
29 # Usually aborts on failure
30 # If errors are explicitly ignored, returns success
31 function wfQuery( $sql, $db, $fname = "" )
33 if ( !is_numeric( $db ) ) {
34 # Someone has tried to call this the old way
35 $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) );
38 return $c->query( $sql, $fname );
41 function &wfGetDB( $db = DB_LAST
)
43 global $wgLoadBalancer;
44 return $wgLoadBalancer->getConnection( $db );
47 # Turns buffering of SQL result sets on (true) or off (false). Default is
48 # "on" and it should not be changed without good reasons.
49 # Returns the previous state.
51 function wfBufferSQLResults( $newstate, $dbi = DB_LAST
)
53 $db =& wfGetDB( $dbi );
54 return $db->setBufferResults( $newstate );
57 # Turns on (false) or off (true) the automatic generation and sending
58 # of a "we're sorry, but there has been a database error" page on
59 # database errors. Default is on (false). When turned off, the
60 # code should use wfLastErrno() and wfLastError() to handle the
61 # situation as appropriate.
62 # Returns the previous state.
64 function wfIgnoreSQLErrors( $newstate, $dbi = DB_LAST
)
66 $db =& wfGetDB( $dbi );
67 return $db->setIgnoreErrors( $newstate );
70 function wfFreeResult( $res, $dbi = DB_LAST
)
72 $db =& wfGetDB( $dbi );
73 $db->freeResult( $res );
76 function wfFetchObject( $res, $dbi = DB_LAST
)
78 $db =& wfGetDB( $dbi );
79 return $db->fetchObject( $res, $dbi = DB_LAST
);
82 function wfFetchRow( $res, $dbi = DB_LAST
)
84 $db =& wfGetDB( $dbi );
85 return $db->fetchRow ( $res, $dbi = DB_LAST
);
88 function wfNumRows( $res, $dbi = DB_LAST
)
90 $db =& wfGetDB( $dbi );
91 return $db->numRows( $res, $dbi = DB_LAST
);
94 function wfNumFields( $res, $dbi = DB_LAST
)
96 $db =& wfGetDB( $dbi );
97 return $db->numFields( $res );
100 function wfFieldName( $res, $n, $dbi = DB_LAST
)
102 $db =& wfGetDB( $dbi );
103 return $db->fieldName( $res, $n, $dbi = DB_LAST
);
106 function wfInsertId( $dbi = DB_LAST
)
108 $db =& wfGetDB( $dbi );
109 return $db->insertId();
111 function wfDataSeek( $res, $row, $dbi = DB_LAST
)
113 $db =& wfGetDB( $dbi );
114 return $db->dataSeek( $res, $row );
117 function wfLastErrno( $dbi = DB_LAST
)
119 $db =& wfGetDB( $dbi );
120 return $db->lastErrno();
123 function wfLastError( $dbi = DB_LAST
)
125 $db =& wfGetDB( $dbi );
126 return $db->lastError();
129 function wfAffectedRows( $dbi = DB_LAST
)
131 $db =& wfGetDB( $dbi );
132 return $db->affectedRows();
135 function wfLastDBquery( $dbi = DB_LAST
)
137 $db =& wfGetDB( $dbi );
138 return $db->lastQuery();
141 function wfSetSQL( $table, $var, $value, $cond, $dbi = DB_WRITE
)
143 $db =& wfGetDB( $dbi );
144 return $db->set( $table, $var, $value, $cond );
147 function wfGetSQL( $table, $var, $cond="", $dbi = DB_LAST
)
149 $db =& wfGetDB( $dbi );
150 return $db->get( $table, $var, $cond );
153 function wfFieldExists( $table, $field, $dbi = DB_LAST
)
155 $db =& wfGetDB( $dbi );
156 return $db->fieldExists( $table, $field );
159 function wfIndexExists( $table, $index, $dbi = DB_LAST
)
161 $db =& wfGetDB( $dbi );
162 return $db->indexExists( $table, $index );
165 function wfInsertArray( $table, $array, $fname = "wfInsertArray", $dbi = DB_WRITE
)
167 $db =& wfGetDB( $dbi );
168 return $db->insertArray( $table, $array, $fname );
171 function wfGetArray( $table, $vars, $conds, $fname = "wfGetArray", $dbi = DB_LAST
)
173 $db =& wfGetDB( $dbi );
174 return $db->getArray( $table, $vars, $conds, $fname );
177 function wfUpdateArray( $table, $values, $conds, $fname = "wfUpdateArray", $dbi = DB_WRITE
)
179 $db =& wfGetDB( $dbi );
180 $db->updateArray( $table, $values, $conds, $fname );