1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WordPress DB Class |
4
|
|
|
* |
5
|
|
|
* Original code from {@link http://php.justinvincent.com Justin Vincent ([email protected])} |
6
|
|
|
* |
7
|
|
|
* @package WordPress |
8
|
|
|
* @subpackage Database |
9
|
|
|
* @since 0.71 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @since 0.71 |
14
|
|
|
*/ |
15
|
|
|
define( 'EZSQL_VERSION', 'WP1.25' ); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @since 0.71 |
19
|
|
|
*/ |
20
|
|
|
define( 'OBJECT', 'OBJECT' ); |
21
|
|
|
// phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase |
22
|
|
|
define( 'object', 'OBJECT' ); // Back compat. |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @since 2.5.0 |
26
|
|
|
*/ |
27
|
|
|
define( 'OBJECT_K', 'OBJECT_K' ); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @since 0.71 |
31
|
|
|
*/ |
32
|
|
|
define( 'ARRAY_A', 'ARRAY_A' ); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @since 0.71 |
36
|
|
|
*/ |
37
|
|
|
define( 'ARRAY_N', 'ARRAY_N' ); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* WordPress Database Access Abstraction Object |
41
|
|
|
* |
42
|
|
|
* It is possible to replace this class with your own |
43
|
|
|
* by setting the $wpdb global variable in wp-content/db.php |
44
|
|
|
* file to your class. The wpdb class will still be included, |
45
|
|
|
* so you can extend it or simply use your own. |
46
|
|
|
* |
47
|
|
|
* @link https://codex.wordpress.org/Function_Reference/wpdb_Class |
48
|
|
|
* |
49
|
|
|
* @since 0.71 |
50
|
|
|
*/ |
51
|
|
|
class mock_wpdb extends wpdb { |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Connects to the database server and selects a database |
57
|
|
|
* |
58
|
|
|
* PHP5 style constructor for compatibility with PHP5. Does |
59
|
|
|
* the actual setting up of the class properties and connection |
60
|
|
|
* to the database. |
61
|
|
|
* |
62
|
|
|
* @link https://core.trac.wordpress.org/ticket/3354 |
63
|
|
|
* @since 2.0.8 |
64
|
|
|
* |
65
|
|
|
* @global string $wp_version The WordPress version string. |
66
|
|
|
* |
67
|
|
|
* @param string $dbuser MySQL database user |
|
|
|
|
68
|
|
|
* @param string $dbpassword MySQL database password |
|
|
|
|
69
|
|
|
* @param string $dbname MySQL database name |
|
|
|
|
70
|
|
|
* @param string $dbhost MySQL database host |
|
|
|
|
71
|
|
|
*/ |
72
|
|
|
public function __construct() { |
73
|
|
|
return; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Change the current SQL mode, and ensure its WordPress compatibility. |
80
|
|
|
* |
81
|
|
|
* If no modes are passed, it will ensure the current MySQL server |
82
|
|
|
* modes are compatible. |
83
|
|
|
* |
84
|
|
|
* @since 3.9.0 |
85
|
|
|
* |
86
|
|
|
* @param array $modes Optional. A list of SQL modes to set. |
87
|
|
|
*/ |
88
|
|
|
public function set_sql_mode( $modes = array() ) { |
89
|
|
|
return; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Selects a database using the current database connection. |
96
|
|
|
* |
97
|
|
|
* The database name will be changed based on the current database |
98
|
|
|
* connection. On failure, the execution will bail and display an DB error. |
99
|
|
|
* |
100
|
|
|
* @since 0.71 |
101
|
|
|
* |
102
|
|
|
* @param string $db MySQL database name |
103
|
|
|
* @param resource|null $dbh Optional link identifier. |
104
|
|
|
*/ |
105
|
|
|
public function select( $db, $dbh = null ) { |
106
|
|
|
return; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Real escape, using mysqli_real_escape_string() or mysql_real_escape_string() |
113
|
|
|
* |
114
|
|
|
* @see mysqli_real_escape_string() |
115
|
|
|
* @see mysql_real_escape_string() |
116
|
|
|
* @since 2.8.0 |
117
|
|
|
* |
118
|
|
|
* @param string $string to escape |
119
|
|
|
* @return string escaped |
120
|
|
|
*/ |
121
|
|
|
function _real_escape( $string ) { |
122
|
|
|
return $this->add_placeholder_escape( $escaped ); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Print SQL/DB error. |
127
|
|
|
* |
128
|
|
|
* @since 0.71 |
129
|
|
|
* @global array $EZSQL_ERROR Stores error information of query and error string. |
130
|
|
|
* |
131
|
|
|
* @param string $str The error to display. |
132
|
|
|
* @return void|false Void if the showing of errors is enabled, false if disabled. |
133
|
|
|
*/ |
134
|
|
|
public function print_error( $str = '' ) { |
135
|
|
|
global $EZSQL_ERROR; |
136
|
|
|
|
137
|
|
|
$EZSQL_ERROR[] = array( |
138
|
|
|
'query' => $this->last_query, |
139
|
|
|
'error_str' => $str, |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
if ( $this->suppress_errors ) { |
143
|
|
|
return false; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$caller = $this->get_caller(); |
147
|
|
|
if ( $caller ) { |
148
|
|
|
/* translators: 1: Database error message, 2: SQL query, 3: Name of the calling function. */ |
149
|
|
|
$error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s', 'jetpack' ), $str, $this->last_query, $caller ); |
150
|
|
|
} else { |
151
|
|
|
/* translators: 1: Database error message, 2: SQL query. */ |
152
|
|
|
$error_str = sprintf( __( 'WordPress database error %1$s for query %2$s', 'jetpack' ), $str, $this->last_query ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
error_log( $error_str ); |
156
|
|
|
|
157
|
|
|
// Are we showing errors? |
158
|
|
|
if ( ! $this->show_errors ) { |
159
|
|
|
return false; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
// If there is an error then take note of it. |
163
|
|
|
if ( is_multisite() ) { |
164
|
|
|
$msg = sprintf( |
165
|
|
|
"%s [%s]\n%s\n", |
166
|
|
|
__( 'WordPress database error:', 'jetpack' ), |
167
|
|
|
$str, |
168
|
|
|
$this->last_query |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
if ( defined( 'ERRORLOGFILE' ) ) { |
172
|
|
|
error_log( $msg, 3, ERRORLOGFILE ); |
173
|
|
|
} |
174
|
|
|
if ( defined( 'DIEONDBERROR' ) ) { |
175
|
|
|
wp_die( $msg ); |
176
|
|
|
} |
177
|
|
|
} else { |
178
|
|
|
$str = htmlspecialchars( $str, ENT_QUOTES ); |
179
|
|
|
$query = htmlspecialchars( $this->last_query, ENT_QUOTES ); |
180
|
|
|
|
181
|
|
|
printf( |
182
|
|
|
'<div id="error"><p class="wpdberror"><strong>%s</strong> [%s]<br /><code>%s</code></p></div>', |
183
|
|
|
__( 'WordPress database error:', 'jetpack' ), |
184
|
|
|
$str, |
185
|
|
|
$query |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Kill cached query results. |
192
|
|
|
* |
193
|
|
|
* @since 0.71 |
194
|
|
|
*/ |
195
|
|
|
public function flush() { |
196
|
|
|
return; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Connect to and select database. |
201
|
|
|
* |
202
|
|
|
* If $allow_bail is false, the lack of database connection will need |
203
|
|
|
* to be handled manually. |
204
|
|
|
* |
205
|
|
|
* @since 3.0.0 |
206
|
|
|
* @since 3.9.0 $allow_bail parameter added. |
207
|
|
|
* |
208
|
|
|
* @param bool $allow_bail Optional. Allows the function to bail. Default true. |
209
|
|
|
* @return bool True with a successful connection, false on failure. |
210
|
|
|
*/ |
211
|
|
|
public function db_connect( $allow_bail = true ) { |
212
|
|
|
return true; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Checks that the connection to the database is still up. If not, try to reconnect. |
217
|
|
|
* |
218
|
|
|
* If this function is unable to reconnect, it will forcibly die, or if after the |
219
|
|
|
* the {@see 'template_redirect'} hook has been fired, return false instead. |
220
|
|
|
* |
221
|
|
|
* If $allow_bail is false, the lack of database connection will need |
222
|
|
|
* to be handled manually. |
223
|
|
|
* |
224
|
|
|
* @since 3.9.0 |
225
|
|
|
* |
226
|
|
|
* @param bool $allow_bail Optional. Allows the function to bail. Default true. |
227
|
|
|
* @return bool|void True if the connection is up. |
228
|
|
|
*/ |
229
|
|
|
public function check_connection( $allow_bail = true ) { |
230
|
|
|
return true; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Perform a MySQL database query, using current database connection. |
235
|
|
|
* |
236
|
|
|
* More information can be found on the codex page. |
237
|
|
|
* |
238
|
|
|
* @since 0.71 |
239
|
|
|
* |
240
|
|
|
* @param string $query Database query |
241
|
|
|
* @return int|bool Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows |
242
|
|
|
* affected/selected for all other queries. Boolean false on error. |
243
|
|
|
*/ |
244
|
|
|
public function query( $query ) { |
245
|
|
|
return array(); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Retrieves the character set for the given column. |
250
|
|
|
* |
251
|
|
|
* @since 4.2.0 |
252
|
|
|
* |
253
|
|
|
* @param string $table Table name. |
254
|
|
|
* @param string $column Column name. |
255
|
|
|
* @return string|false|WP_Error Column character set as a string. False if the column has no |
256
|
|
|
* character set. WP_Error object if there was an error. |
257
|
|
|
*/ |
258
|
|
|
public function get_col_charset( $table, $column ) { |
259
|
|
|
return 'UTF-8'; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Load the column metadata from the last query. |
264
|
|
|
* |
265
|
|
|
* @since 3.5.0 |
266
|
|
|
*/ |
267
|
|
|
protected function load_col_info() { |
268
|
|
|
|
269
|
|
|
return; |
270
|
|
|
|
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Wraps errors in a nice header and footer and dies. |
275
|
|
|
* |
276
|
|
|
* Will not die if wpdb::$show_errors is false. |
277
|
|
|
* |
278
|
|
|
* @since 1.5.0 |
279
|
|
|
* |
280
|
|
|
* @param string $message The error message. |
281
|
|
|
* @param string $error_code Optional. A computer-readable string to identify the error. |
282
|
|
|
* @return void|false Void if the showing of errors is enabled, false if disabled. |
283
|
|
|
*/ |
284
|
|
|
public function bail( $message, $error_code = '500' ) { |
285
|
|
|
return false; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Closes the current database connection. |
291
|
|
|
* |
292
|
|
|
* @since 4.5.0 |
293
|
|
|
* |
294
|
|
|
* @return bool True if the connection was successfully closed, false if it wasn't, |
295
|
|
|
* or the connection doesn't exist. |
296
|
|
|
*/ |
297
|
|
|
public function close() { |
298
|
|
|
return true; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Determine if a database supports a particular feature. |
303
|
|
|
* |
304
|
|
|
* @since 2.7.0 |
305
|
|
|
* @since 4.1.0 Added support for the 'utf8mb4' feature. |
306
|
|
|
* @since 4.6.0 Added support for the 'utf8mb4_520' feature. |
307
|
|
|
* |
308
|
|
|
* @see wpdb::db_version() |
309
|
|
|
* |
310
|
|
|
* @param string $db_cap The feature to check for. Accepts 'collation', |
311
|
|
|
* 'group_concat', 'subqueries', 'set_charset', |
312
|
|
|
* 'utf8mb4', or 'utf8mb4_520'. |
313
|
|
|
* @return int|false Whether the database feature is supported, false otherwise. |
314
|
|
|
*/ |
315
|
|
|
public function has_cap( $db_cap ) { |
316
|
|
|
return true; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Retrieves the MySQL server version. |
322
|
|
|
* |
323
|
|
|
* @since 2.7.0 |
324
|
|
|
* |
325
|
|
|
* @return null|string Null on failure, version number on success. |
326
|
|
|
*/ |
327
|
|
|
public function db_version() { |
328
|
|
|
return 10; |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
global $wpdb; |
333
|
|
|
$wpdb = new mock_wpdb(); |
334
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.