* Recent Changes improvements: object oriented back end, move page annotation and...
[lhc/web/wiklou.git] / includes / DatabaseFunctions.php
index b3208e1..0add9fd 100644 (file)
@@ -2,8 +2,16 @@
 
 # Backwards compatibility wrapper for Database.php
 
+# I imagine this file will eventually become a backwards
+# compatibility wrapper around a load balancer object, and
+# the load balancer will finally call Database, which will
+# represent a single connection
+
 # NB: This file follows a connect on demand scheme. Do 
-# not access the $wgDatabase variable directly, use wfGetDB()
+# not access the $wgDatabase variable directly unless
+# you intend to set it. Use wfGetDB().
+
+include_once( "Database.php" );
 
 # Query the database
 # $db: DB_READ  = -1    read from slave (or only server)
@@ -12,9 +20,6 @@
 # Replication is not actually implemented just yet
 # Usually aborts on failure
 # If errors are explicitly ignored, returns success
-
-include_once( "Database.php" );
-
 function wfQuery( $sql, $db, $fname = "" )
 {
        global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 
@@ -25,12 +30,12 @@ function wfQuery( $sql, $db, $fname = "" )
                $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) );
        }
 
-       $db = wfGetDB();
-       return $db->query( $sql, $db, $fname );
+       $db = wfGetDB();
+       return $db->query( $sql, $fname );
 }
 
 # Connect on demand
-function wfGetDB()
+function &wfGetDB()
 {
        global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 
                $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
@@ -47,7 +52,7 @@ function wfGetDB()
 
 function wfBufferSQLResults( $newstate )
 {
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->setBufferResults( $newstate );
 }
 
@@ -60,97 +65,109 @@ function wfBufferSQLResults( $newstate )
 
 function wfIgnoreSQLErrors( $newstate )
 {
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->setIgnoreErrors( $newstate );
 }
 
 function wfFreeResult( $res ) 
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        $db->freeResult( $res ); 
 }
 
 function wfFetchObject( $res ) 
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->fetchObject( $res ); 
 }
 
 function wfNumRows( $res ) 
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->numRows( $res ); 
 }
 
 function wfNumFields( $res ) 
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->numFields( $res ); 
 }
 
 function wfFieldName( $res, $n ) 
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->fieldName( $res, $n ); 
 }
 
 function wfInsertId() 
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->insertId(); 
 }
 function wfDataSeek( $res, $row ) 
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->dataSeek( $res, $row ); 
 }
 
 function wfLastErrno()  
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->lastErrno(); 
 }
 
 function wfLastError()  
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->lastError(); 
 }
 
 function wfAffectedRows()
 { 
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->affectedRows(); 
 }
 
 function wfLastDBquery()
 {
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->lastQuery();
 }
 
 function wfSetSQL( $table, $var, $value, $cond )
 {
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->set( $table, $var, $value, $cond );
 }
 
 function wfGetSQL( $table, $var, $cond )
 {
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->get( $table, $var, $cond );
 }
 
 function wfFieldExists( $table, $field )
 {
-       $db = wfGetDB();
+       $db =& wfGetDB();
        return $db->fieldExists( $table, $field );
 }
 
 function wfIndexExists( $table, $index ) 
 {
-       $db = wfGetDB();
-       return $wgDatabase->indexExists( $table, $index );
+       $db =& wfGetDB();
+       return $db->indexExists( $table, $index );
+}
+
+function wfInsertArray( $table, $array ) 
+{
+       $db =& wfGetDB();
+       return $db->insertArray( $table, $array );
+}
+
+function wfGetArray( $table, $vars, $conds, $fname = "wfGetArray" )
+{
+       $db =& wfGetDB();
+       return $db->getArray( $table, $vars, $conds, $fname );
 }
 
 ?>