2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
# Backwards compatibility wrapper for Database.php
|
2003-09-20 02:30:00 +00:00
|
|
|
|
2004-01-17 05:49:39 +00:00
|
|
|
# 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
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
# NB: This file follows a connect on demand scheme. Do
|
2004-01-17 05:49:39 +00:00
|
|
|
# not access the $wgDatabase variable directly unless
|
|
|
|
|
# you intend to set it. Use wfGetDB().
|
|
|
|
|
|
|
|
|
|
include_once( "Database.php" );
|
2003-08-02 10:13:27 +00:00
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
# Query the database
|
2003-09-20 02:30:00 +00:00
|
|
|
# $db: DB_READ = -1 read from slave (or only server)
|
|
|
|
|
# DB_WRITE = -2 write to master (or only server)
|
|
|
|
|
# 0,1,2,... query a database with a specific index
|
|
|
|
|
# Replication is not actually implemented just yet
|
2004-01-10 16:44:31 +00:00
|
|
|
# Usually aborts on failure
|
|
|
|
|
# If errors are explicitly ignored, returns success
|
|
|
|
|
function wfQuery( $sql, $db, $fname = "" )
|
|
|
|
|
{
|
|
|
|
|
global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname,
|
|
|
|
|
$wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
|
|
|
|
|
|
2003-11-02 13:57:24 +00:00
|
|
|
if ( !is_numeric( $db ) ) {
|
|
|
|
|
# Someone has tried to call this the old way
|
2003-11-09 11:45:12 +00:00
|
|
|
$wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) );
|
2003-11-02 13:57:24 +00:00
|
|
|
}
|
2003-11-09 11:45:12 +00:00
|
|
|
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
|
|
|
|
return $db->query( $sql, $fname );
|
2004-01-10 16:44:31 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
# Connect on demand
|
2004-01-17 05:49:39 +00:00
|
|
|
function &wfGetDB()
|
2004-01-10 16:44:31 +00:00
|
|
|
{
|
|
|
|
|
global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname,
|
|
|
|
|
$wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
|
|
|
|
|
if ( !$wgDatabase ) {
|
|
|
|
|
$wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword,
|
|
|
|
|
$wgDBname, false, $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors );
|
2003-11-21 06:23:54 +00:00
|
|
|
}
|
2004-01-10 16:44:31 +00:00
|
|
|
return $wgDatabase;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-01-10 16:44:31 +00:00
|
|
|
|
2003-12-13 20:26:47 +00:00
|
|
|
# Turns buffering of SQL result sets on (true) or off (false). Default is
|
|
|
|
|
# "on" and it should not be changed without good reasons.
|
|
|
|
|
# Returns the previous state.
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfBufferSQLResults( $newstate )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->setBufferResults( $newstate );
|
2003-12-13 20:26:47 +00:00
|
|
|
}
|
2003-11-24 19:33:26 +00:00
|
|
|
|
2003-12-13 20:26:47 +00:00
|
|
|
# Turns on (false) or off (true) the automatic generation and sending
|
|
|
|
|
# of a "we're sorry, but there has been a database error" page on
|
|
|
|
|
# database errors. Default is on (false). When turned off, the
|
|
|
|
|
# code should use wfLastErrno() and wfLastError() to handle the
|
|
|
|
|
# situation as appropriate.
|
|
|
|
|
# Returns the previous state.
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfIgnoreSQLErrors( $newstate )
|
2003-04-14 23:10:40 +00:00
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->setIgnoreErrors( $newstate );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfFreeResult( $res )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
$db->freeResult( $res );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfFetchObject( $res )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->fetchObject( $res );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfNumRows( $res )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->numRows( $res );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfNumFields( $res )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->numFields( $res );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfFieldName( $res, $n )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->fieldName( $res, $n );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfInsertId()
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->insertId();
|
|
|
|
|
}
|
|
|
|
|
function wfDataSeek( $res, $row )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->dataSeek( $res, $row );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfLastErrno()
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->lastErrno();
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfLastError()
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->lastError();
|
|
|
|
|
}
|
2003-12-01 00:28:25 +00:00
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfAffectedRows()
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->affectedRows();
|
|
|
|
|
}
|
2003-12-01 00:28:25 +00:00
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfLastDBquery()
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->lastQuery();
|
|
|
|
|
}
|
2003-12-01 00:28:25 +00:00
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfSetSQL( $table, $var, $value, $cond )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->set( $table, $var, $value, $cond );
|
|
|
|
|
}
|
2003-12-01 00:28:25 +00:00
|
|
|
|
2004-01-10 16:44:31 +00:00
|
|
|
function wfGetSQL( $table, $var, $cond )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->get( $table, $var, $cond );
|
2003-11-18 23:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-09 11:45:12 +00:00
|
|
|
function wfFieldExists( $table, $field )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$db =& wfGetDB();
|
2004-01-10 16:44:31 +00:00
|
|
|
return $db->fieldExists( $table, $field );
|
2003-11-09 11:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wfIndexExists( $table, $index )
|
|
|
|
|
{
|
2004-01-17 05:49:39 +00:00
|
|
|
$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 );
|
2003-11-09 11:45:12 +00:00
|
|
|
}
|
2004-01-10 16:44:31 +00:00
|
|
|
|
2004-03-23 10:17:50 +00:00
|
|
|
function wfUpdateArray( $table, $values, $conds, $fname = "wfUpdateArray" )
|
|
|
|
|
{
|
|
|
|
|
$db =& wfGetDB();
|
|
|
|
|
$db->updateArray( $table, $values, $conds, $fname );
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
?>
|