A few language files from some of the larger Wikipedias, extracted from the MediaWiki...
[mediawiki.git] / includes / DatabaseFunctions.php
blob3b92eaa1eb829994a631d338cd36bdb36fdbbfa5
1 <?php
2 # $Id$
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().
15 $wgIsMySQL=false;
16 $wgIsPg=false;
18 if ($wgDBtype=="mysql") {
19 require_once( "Database.php" );
20 $wgIsMySQL=true;
21 } elseif ($wgDBtype=="pgsql") {
22 require_once( "DatabasePostgreSQL.php" );
23 $wgIsPg=true;
26 # Query the database
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 ) );
43 $db =& wfGetDB();
44 return $db->query( $sql, $fname );
47 # Connect on demand
48 function &wfGetDB()
50 global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname,
51 $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
52 if ( !$wgDatabase ) {
53 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword,
54 $wgDBname, false, $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors );
56 return $wgDatabase;
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 )
65 $db =& wfGetDB();
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 )
78 $db =& wfGetDB();
79 return $db->setIgnoreErrors( $newstate );
82 function wfFreeResult( $res )
84 $db =& wfGetDB();
85 $db->freeResult( $res );
88 function wfFetchObject( $res )
90 $db =& wfGetDB();
91 return $db->fetchObject( $res );
94 function wfFetchRow( $res )
96 $db =& wfGetDB();
97 return $db->fetchRow ( $res );
100 function wfNumRows( $res )
102 $db =& wfGetDB();
103 return $db->numRows( $res );
106 function wfNumFields( $res )
108 $db =& wfGetDB();
109 return $db->numFields( $res );
112 function wfFieldName( $res, $n )
114 $db =& wfGetDB();
115 return $db->fieldName( $res, $n );
118 function wfInsertId()
120 $db =& wfGetDB();
121 return $db->insertId();
123 function wfDataSeek( $res, $row )
125 $db =& wfGetDB();
126 return $db->dataSeek( $res, $row );
129 function wfLastErrno()
131 $db =& wfGetDB();
132 return $db->lastErrno();
135 function wfLastError()
137 $db =& wfGetDB();
138 return $db->lastError();
141 function wfAffectedRows()
143 $db =& wfGetDB();
144 return $db->affectedRows();
147 function wfLastDBquery()
149 $db =& wfGetDB();
150 return $db->lastQuery();
153 function wfSetSQL( $table, $var, $value, $cond )
155 $db =& wfGetDB();
156 return $db->set( $table, $var, $value, $cond );
159 function wfGetSQL( $table, $var, $cond="" )
161 $db =& wfGetDB();
162 return $db->get( $table, $var, $cond );
165 function wfFieldExists( $table, $field )
167 $db =& wfGetDB();
168 return $db->fieldExists( $table, $field );
171 function wfIndexExists( $table, $index )
173 $db =& wfGetDB();
174 return $db->indexExists( $table, $index );
177 function wfInsertArray( $table, $array )
179 $db =& wfGetDB();
180 return $db->insertArray( $table, $array );
183 function wfGetArray( $table, $vars, $conds, $fname = "wfGetArray" )
185 $db =& wfGetDB();
186 return $db->getArray( $table, $vars, $conds, $fname );
189 function wfUpdateArray( $table, $values, $conds, $fname = "wfUpdateArray" )
191 $db =& wfGetDB();
192 $db->updateArray( $table, $values, $conds, $fname );