new function wfUpdateArray()
[lhc/web/wiklou.git] / includes / DatabaseFunctions.php
1 <?php
2
3 # Backwards compatibility wrapper for Database.php
4
5 # I imagine this file will eventually become a backwards
6 # compatibility wrapper around a load balancer object, and
7 # the load balancer will finally call Database, which will
8 # represent a single connection
9
10 # NB: This file follows a connect on demand scheme. Do
11 # not access the $wgDatabase variable directly unless
12 # you intend to set it. Use wfGetDB().
13
14 include_once( "Database.php" );
15
16 # Query the database
17 # $db: DB_READ = -1 read from slave (or only server)
18 # DB_WRITE = -2 write to master (or only server)
19 # 0,1,2,... query a database with a specific index
20 # Replication is not actually implemented just yet
21 # Usually aborts on failure
22 # If errors are explicitly ignored, returns success
23 function wfQuery( $sql, $db, $fname = "" )
24 {
25 global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname,
26 $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
27
28 if ( !is_numeric( $db ) ) {
29 # Someone has tried to call this the old way
30 $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) );
31 }
32
33 $db =& wfGetDB();
34 return $db->query( $sql, $fname );
35 }
36
37 # Connect on demand
38 function &wfGetDB()
39 {
40 global $wgDatabase, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname,
41 $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors;
42 if ( !$wgDatabase ) {
43 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword,
44 $wgDBname, false, $wgDebugDumpSql, $wgBufferSQLResults, $wgIgnoreSQLErrors );
45 }
46 return $wgDatabase;
47 }
48
49 # Turns buffering of SQL result sets on (true) or off (false). Default is
50 # "on" and it should not be changed without good reasons.
51 # Returns the previous state.
52
53 function wfBufferSQLResults( $newstate )
54 {
55 $db =& wfGetDB();
56 return $db->setBufferResults( $newstate );
57 }
58
59 # Turns on (false) or off (true) the automatic generation and sending
60 # of a "we're sorry, but there has been a database error" page on
61 # database errors. Default is on (false). When turned off, the
62 # code should use wfLastErrno() and wfLastError() to handle the
63 # situation as appropriate.
64 # Returns the previous state.
65
66 function wfIgnoreSQLErrors( $newstate )
67 {
68 $db =& wfGetDB();
69 return $db->setIgnoreErrors( $newstate );
70 }
71
72 function wfFreeResult( $res )
73 {
74 $db =& wfGetDB();
75 $db->freeResult( $res );
76 }
77
78 function wfFetchObject( $res )
79 {
80 $db =& wfGetDB();
81 return $db->fetchObject( $res );
82 }
83
84 function wfNumRows( $res )
85 {
86 $db =& wfGetDB();
87 return $db->numRows( $res );
88 }
89
90 function wfNumFields( $res )
91 {
92 $db =& wfGetDB();
93 return $db->numFields( $res );
94 }
95
96 function wfFieldName( $res, $n )
97 {
98 $db =& wfGetDB();
99 return $db->fieldName( $res, $n );
100 }
101
102 function wfInsertId()
103 {
104 $db =& wfGetDB();
105 return $db->insertId();
106 }
107 function wfDataSeek( $res, $row )
108 {
109 $db =& wfGetDB();
110 return $db->dataSeek( $res, $row );
111 }
112
113 function wfLastErrno()
114 {
115 $db =& wfGetDB();
116 return $db->lastErrno();
117 }
118
119 function wfLastError()
120 {
121 $db =& wfGetDB();
122 return $db->lastError();
123 }
124
125 function wfAffectedRows()
126 {
127 $db =& wfGetDB();
128 return $db->affectedRows();
129 }
130
131 function wfLastDBquery()
132 {
133 $db =& wfGetDB();
134 return $db->lastQuery();
135 }
136
137 function wfSetSQL( $table, $var, $value, $cond )
138 {
139 $db =& wfGetDB();
140 return $db->set( $table, $var, $value, $cond );
141 }
142
143 function wfGetSQL( $table, $var, $cond )
144 {
145 $db =& wfGetDB();
146 return $db->get( $table, $var, $cond );
147 }
148
149 function wfFieldExists( $table, $field )
150 {
151 $db =& wfGetDB();
152 return $db->fieldExists( $table, $field );
153 }
154
155 function wfIndexExists( $table, $index )
156 {
157 $db =& wfGetDB();
158 return $db->indexExists( $table, $index );
159 }
160
161 function wfInsertArray( $table, $array )
162 {
163 $db =& wfGetDB();
164 return $db->insertArray( $table, $array );
165 }
166
167 function wfGetArray( $table, $vars, $conds, $fname = "wfGetArray" )
168 {
169 $db =& wfGetDB();
170 return $db->getArray( $table, $vars, $conds, $fname );
171 }
172
173 function wfUpdateArray( $table, $values, $conds, $fname = "wfUpdateArray" )
174 {
175 $db =& wfGetDB();
176 $db->updateArray( $table, $values, $conds, $fname );
177 }
178
179 ?>