Bringing the load balancer to the main branch. Still doesn't do much. I needed a...
[lhc/web/wiklou.git] / includes / DatabaseFunctions.php
1 <?php
2 # $Id$
3
4 # Backwards compatibility wrapper for Database.php
5
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
10
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().
14 $wgDatabase = false;
15
16 $wgIsMySQL=false;
17 $wgIsPg=false;
18
19 if ($wgDBtype=="mysql") {
20 require_once( "Database.php" );
21 $wgIsMySQL=true;
22 } elseif ($wgDBtype=="pgsql") {
23 require_once( "DatabasePostgreSQL.php" );
24 $wgIsPg=true;
25 }
26
27
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 = "" )
32 {
33 if ( !is_numeric( $db ) ) {
34 # Someone has tried to call this the old way
35 $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) );
36 }
37 $c =& wfGetDB( $db );
38 return $c->query( $sql, $fname );
39 }
40
41 function &wfGetDB( $db = DB_LAST )
42 {
43 global $wgLoadBalancer;
44 return $wgLoadBalancer->getConnection( $db );
45 }
46
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.
50
51 function wfBufferSQLResults( $newstate, $dbi = DB_LAST )
52 {
53 $db =& wfGetDB( $dbi );
54 return $db->setBufferResults( $newstate );
55 }
56
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.
63
64 function wfIgnoreSQLErrors( $newstate, $dbi = DB_LAST )
65 {
66 $db =& wfGetDB( $dbi );
67 return $db->setIgnoreErrors( $newstate );
68 }
69
70 function wfFreeResult( $res, $dbi = DB_LAST )
71 {
72 $db =& wfGetDB( $dbi );
73 $db->freeResult( $res );
74 }
75
76 function wfFetchObject( $res, $dbi = DB_LAST )
77 {
78 $db =& wfGetDB( $dbi );
79 return $db->fetchObject( $res, $dbi = DB_LAST );
80 }
81
82 function wfFetchRow( $res, $dbi = DB_LAST )
83 {
84 $db =& wfGetDB( $dbi );
85 return $db->fetchRow ( $res, $dbi = DB_LAST );
86 }
87
88 function wfNumRows( $res, $dbi = DB_LAST )
89 {
90 $db =& wfGetDB( $dbi );
91 return $db->numRows( $res, $dbi = DB_LAST );
92 }
93
94 function wfNumFields( $res, $dbi = DB_LAST )
95 {
96 $db =& wfGetDB( $dbi );
97 return $db->numFields( $res );
98 }
99
100 function wfFieldName( $res, $n, $dbi = DB_LAST )
101 {
102 $db =& wfGetDB( $dbi );
103 return $db->fieldName( $res, $n, $dbi = DB_LAST );
104 }
105
106 function wfInsertId( $dbi = DB_LAST )
107 {
108 $db =& wfGetDB( $dbi );
109 return $db->insertId();
110 }
111 function wfDataSeek( $res, $row, $dbi = DB_LAST )
112 {
113 $db =& wfGetDB( $dbi );
114 return $db->dataSeek( $res, $row );
115 }
116
117 function wfLastErrno( $dbi = DB_LAST )
118 {
119 $db =& wfGetDB( $dbi );
120 return $db->lastErrno();
121 }
122
123 function wfLastError( $dbi = DB_LAST )
124 {
125 $db =& wfGetDB( $dbi );
126 return $db->lastError();
127 }
128
129 function wfAffectedRows( $dbi = DB_LAST )
130 {
131 $db =& wfGetDB( $dbi );
132 return $db->affectedRows();
133 }
134
135 function wfLastDBquery( $dbi = DB_LAST )
136 {
137 $db =& wfGetDB( $dbi );
138 return $db->lastQuery();
139 }
140
141 function wfSetSQL( $table, $var, $value, $cond, $dbi = DB_WRITE )
142 {
143 $db =& wfGetDB( $dbi );
144 return $db->set( $table, $var, $value, $cond );
145 }
146
147 function wfGetSQL( $table, $var, $cond="", $dbi = DB_LAST )
148 {
149 $db =& wfGetDB( $dbi );
150 return $db->get( $table, $var, $cond );
151 }
152
153 function wfFieldExists( $table, $field, $dbi = DB_LAST )
154 {
155 $db =& wfGetDB( $dbi );
156 return $db->fieldExists( $table, $field );
157 }
158
159 function wfIndexExists( $table, $index, $dbi = DB_LAST )
160 {
161 $db =& wfGetDB( $dbi );
162 return $db->indexExists( $table, $index );
163 }
164
165 function wfInsertArray( $table, $array, $fname = "wfInsertArray", $dbi = DB_WRITE )
166 {
167 $db =& wfGetDB( $dbi );
168 return $db->insertArray( $table, $array, $fname );
169 }
170
171 function wfGetArray( $table, $vars, $conds, $fname = "wfGetArray", $dbi = DB_LAST )
172 {
173 $db =& wfGetDB( $dbi );
174 return $db->getArray( $table, $vars, $conds, $fname );
175 }
176
177 function wfUpdateArray( $table, $values, $conds, $fname = "wfUpdateArray", $dbi = DB_WRITE )
178 {
179 $db =& wfGetDB( $dbi );
180 $db->updateArray( $table, $values, $conds, $fname );
181 }
182
183 ?>