CatPtain commited on
Commit
1fb22f2
Β·
verified Β·
1 Parent(s): efc9636

Upload 2 files

Browse files
Files changed (2) hide show
  1. db.php +205 -0
  2. test-php.php +37 -0
db.php CHANGED
@@ -46,14 +46,25 @@ class SQLite_DB {
46
  public $terms;
47
  public $term_taxonomy;
48
  public $term_relationships;
 
49
  public $comments;
50
  public $commentmeta;
 
 
 
 
 
 
51
 
52
  public function __construct() {
53
  global $table_prefix;
54
  $this->prefix = isset($table_prefix) ? $table_prefix : 'wp_';
 
 
 
55
  $this->set_table_names();
56
  $this->connect();
 
57
  }
58
 
59
  private function set_table_names() {
@@ -65,8 +76,10 @@ class SQLite_DB {
65
  $this->terms = $this->prefix . 'terms';
66
  $this->term_taxonomy = $this->prefix . 'term_taxonomy';
67
  $this->term_relationships = $this->prefix . 'term_relationships';
 
68
  $this->comments = $this->prefix . 'comments';
69
  $this->commentmeta = $this->prefix . 'commentmeta';
 
70
  }
71
 
72
  private function connect() {
@@ -205,6 +218,198 @@ class SQLite_DB {
205
  echo '<div id="error"><p class="wpdberror"><strong>WordPress database error:</strong> [' . $this->last_error . ']<br /><code>' . $this->last_query . '</code></p></div>';
206
  }
207
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  }
209
 
210
  // Initialize SQLite database connection
 
46
  public $terms;
47
  public $term_taxonomy;
48
  public $term_relationships;
49
+ public $termmeta;
50
  public $comments;
51
  public $commentmeta;
52
+ public $links;
53
+ public $field_types = array();
54
+ public $charset;
55
+ public $collate;
56
+ public $dbname;
57
+ public $ready = false;
58
 
59
  public function __construct() {
60
  global $table_prefix;
61
  $this->prefix = isset($table_prefix) ? $table_prefix : 'wp_';
62
+ $this->charset = 'utf8';
63
+ $this->collate = '';
64
+ $this->dbname = 'wordpress';
65
  $this->set_table_names();
66
  $this->connect();
67
+ $this->ready = true;
68
  }
69
 
70
  private function set_table_names() {
 
76
  $this->terms = $this->prefix . 'terms';
77
  $this->term_taxonomy = $this->prefix . 'term_taxonomy';
78
  $this->term_relationships = $this->prefix . 'term_relationships';
79
+ $this->termmeta = $this->prefix . 'termmeta';
80
  $this->comments = $this->prefix . 'comments';
81
  $this->commentmeta = $this->prefix . 'commentmeta';
82
+ $this->links = $this->prefix . 'links';
83
  }
84
 
85
  private function connect() {
 
218
  echo '<div id="error"><p class="wpdberror"><strong>WordPress database error:</strong> [' . $this->last_error . ']<br /><code>' . $this->last_query . '</code></p></div>';
219
  }
220
  }
221
+
222
+ // WordPress required methods
223
+ public function set_prefix($prefix, $set_table_names = true) {
224
+ if (preg_match('|[^a-z0-9_]|i', $prefix)) {
225
+ // Return false instead of WP_Error since WP_Error might not be available yet
226
+ return false;
227
+ }
228
+
229
+ $old_prefix = $this->prefix;
230
+ $this->prefix = $prefix;
231
+
232
+ if ($set_table_names) {
233
+ $this->set_table_names();
234
+ }
235
+
236
+ return $old_prefix;
237
+ }
238
+
239
+ public function set_blog_id($blog_id, $network_id = 0) {
240
+ // For single site, just return
241
+ return $this->prefix;
242
+ }
243
+
244
+ public function get_blog_prefix($blog_id = null) {
245
+ return $this->prefix;
246
+ }
247
+
248
+ public function tables($scope = 'all', $prefix = true, $blog_id = 0) {
249
+ $tables = array(
250
+ 'posts', 'comments', 'links', 'options', 'postmeta',
251
+ 'terms', 'term_taxonomy', 'term_relationships', 'termmeta',
252
+ 'commentmeta', 'users', 'usermeta'
253
+ );
254
+
255
+ if ($prefix) {
256
+ $prefixed_tables = array();
257
+ foreach ($tables as $table) {
258
+ $prefixed_tables[] = $this->prefix . $table;
259
+ }
260
+ return $prefixed_tables;
261
+ }
262
+
263
+ return $tables;
264
+ }
265
+
266
+ public function get_table_charset($table) {
267
+ return 'utf8';
268
+ }
269
+
270
+ public function get_col_charset($table, $column) {
271
+ return 'utf8';
272
+ }
273
+
274
+ public function check_connection($allow_bail = true) {
275
+ return true;
276
+ }
277
+
278
+ public function db_version() {
279
+ return $this->get_var('SELECT sqlite_version()');
280
+ }
281
+
282
+ public function flush() {
283
+ $this->last_result = null;
284
+ $this->last_query = null;
285
+ $this->last_error = '';
286
+ }
287
+
288
+ public function close() {
289
+ $this->pdo = null;
290
+ return true;
291
+ }
292
+
293
+ public function has_cap($db_cap) {
294
+ switch (strtolower($db_cap)) {
295
+ case 'collation':
296
+ case 'group_concat':
297
+ case 'subqueries':
298
+ return true;
299
+ default:
300
+ return false;
301
+ }
302
+ }
303
+
304
+ public function get_caller() {
305
+ if (function_exists('wp_debug_backtrace_summary')) {
306
+ return wp_debug_backtrace_summary(__CLASS__);
307
+ }
308
+ return '';
309
+ }
310
+
311
+ public function init_charset() {
312
+ // SQLite uses UTF-8 by default
313
+ return true;
314
+ }
315
+
316
+ public function set_charset($dbh, $charset = null, $collate = null) {
317
+ // SQLite uses UTF-8 by default
318
+ return true;
319
+ }
320
+
321
+ // WordPress data manipulation methods
322
+ public function insert($table, $data, $format = null) {
323
+ return $this->_insert_replace_helper($table, $data, $format, 'INSERT');
324
+ }
325
+
326
+ public function replace($table, $data, $format = null) {
327
+ return $this->_insert_replace_helper($table, $data, $format, 'REPLACE');
328
+ }
329
+
330
+ public function update($table, $data, $where, $format = null, $where_format = null) {
331
+ if (!is_array($data) || !is_array($where)) {
332
+ return false;
333
+ }
334
+
335
+ $formats = $format = (array) $format;
336
+ $bits = $wheres = array();
337
+ foreach ((array) array_keys($data) as $field) {
338
+ if (!empty($formats)) {
339
+ $form = ($form = array_shift($formats)) ? $form : $formats[0];
340
+ } elseif (isset($this->field_types[$field])) {
341
+ $form = $this->field_types[$field];
342
+ } else {
343
+ $form = '%s';
344
+ }
345
+ $bits[] = "`$field` = {$form}";
346
+ }
347
+
348
+ $where_formats = $where_format = (array) $where_format;
349
+ foreach ((array) array_keys($where) as $field) {
350
+ if (!empty($where_formats)) {
351
+ $form = ($form = array_shift($where_formats)) ? $form : $where_formats[0];
352
+ } elseif (isset($this->field_types[$field])) {
353
+ $form = $this->field_types[$field];
354
+ } else {
355
+ $form = '%s';
356
+ }
357
+ $wheres[] = "`$field` = {$form}";
358
+ }
359
+
360
+ $sql = "UPDATE `$table` SET " . implode(', ', $bits) . ' WHERE ' . implode(' AND ', $wheres);
361
+ return $this->query($this->prepare($sql, array_merge(array_values($data), array_values($where))));
362
+ }
363
+
364
+ public function delete($table, $where, $where_format = null) {
365
+ if (!is_array($where)) {
366
+ return false;
367
+ }
368
+
369
+ $where_formats = $where_format = (array) $where_format;
370
+ $wheres = array();
371
+ foreach (array_keys($where) as $field) {
372
+ if (!empty($where_formats)) {
373
+ $form = ($form = array_shift($where_formats)) ? $form : $where_formats[0];
374
+ } elseif (isset($this->field_types[$field])) {
375
+ $form = $this->field_types[$field];
376
+ } else {
377
+ $form = '%s';
378
+ }
379
+ $wheres[] = "`$field` = {$form}";
380
+ }
381
+
382
+ $sql = "DELETE FROM `$table` WHERE " . implode(' AND ', $wheres);
383
+ return $this->query($this->prepare($sql, array_values($where)));
384
+ }
385
+
386
+ private function _insert_replace_helper($table, $data, $format = null, $type = 'INSERT') {
387
+ if (!in_array(strtoupper($type), array('INSERT', 'REPLACE'))) {
388
+ return false;
389
+ }
390
+
391
+ if (!is_array($data)) {
392
+ return false;
393
+ }
394
+
395
+ $formats = $format = (array) $format;
396
+ $fields = array_keys($data);
397
+ $formatted_fields = array();
398
+
399
+ foreach ($fields as $field) {
400
+ if (!empty($formats)) {
401
+ $form = ($form = array_shift($formats)) ? $form : $formats[0];
402
+ } elseif (isset($this->field_types[$field])) {
403
+ $form = $this->field_types[$field];
404
+ } else {
405
+ $form = '%s';
406
+ }
407
+ $formatted_fields[] = $form;
408
+ }
409
+
410
+ $sql = "$type INTO `$table` (`" . implode('`,`', $fields) . '`) VALUES (' . implode(',', $formatted_fields) . ')';
411
+ return $this->query($this->prepare($sql, array_values($data)));
412
+ }
413
  }
414
 
415
  // Initialize SQLite database connection
test-php.php CHANGED
@@ -50,6 +50,43 @@ foreach ($files as $file) {
50
  }
51
  }
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  echo "<hr>";
54
  echo "<p><a href='/'>Try WordPress</a> | <a href='/debug.php'>Debug Info</a></p>";
55
  ?>
 
50
  }
51
  }
52
 
53
+ // Test WordPress database methods
54
+ echo "<h2>WordPress Database Methods Test</h2>";
55
+ if (file_exists('/var/www/html/wp-content/db.php')) {
56
+ require_once('/var/www/html/wp-content/db.php');
57
+
58
+ if (class_exists('SQLite_DB')) {
59
+ $test_db = new SQLite_DB();
60
+
61
+ echo "<p>βœ“ SQLite_DB class loaded successfully</p>";
62
+
63
+ // Test required methods
64
+ $methods = ['set_prefix', 'get_results', 'get_row', 'get_var', 'prepare', 'insert', 'update', 'delete'];
65
+ foreach ($methods as $method) {
66
+ if (method_exists($test_db, $method)) {
67
+ echo "<p style='color: green;'>βœ“ Method $method exists</p>";
68
+ } else {
69
+ echo "<p style='color: red;'>βœ— Method $method missing</p>";
70
+ }
71
+ }
72
+
73
+ // Test properties
74
+ $properties = ['prefix', 'posts', 'users', 'options', 'ready', 'field_types'];
75
+ foreach ($properties as $prop) {
76
+ if (property_exists($test_db, $prop)) {
77
+ echo "<p style='color: green;'>βœ“ Property $prop exists</p>";
78
+ } else {
79
+ echo "<p style='color: red;'>βœ— Property $prop missing</p>";
80
+ }
81
+ }
82
+
83
+ } else {
84
+ echo "<p style='color: red;'>βœ— SQLite_DB class not found</p>";
85
+ }
86
+ } else {
87
+ echo "<p style='color: red;'>βœ— wp-content/db.php not found</p>";
88
+ }
89
+
90
  echo "<hr>";
91
  echo "<p><a href='/'>Try WordPress</a> | <a href='/debug.php'>Debug Info</a></p>";
92
  ?>