Upload db.php
Browse files
db.php
CHANGED
@@ -31,6 +31,7 @@ if (!file_exists($db_dir)) {
|
|
31 |
class SQLite_DB {
|
32 |
public $pdo;
|
33 |
public $last_error = '';
|
|
|
34 |
public $insert_id = 0;
|
35 |
public $num_rows = 0;
|
36 |
public $last_query = '';
|
@@ -68,10 +69,15 @@ class SQLite_DB {
|
|
68 |
$this->collate = '';
|
69 |
$this->dbname = '/var/www/html/wp-content/database';
|
70 |
$this->set_table_names();
|
71 |
-
|
72 |
-
$this->
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
|
77 |
private function set_table_names() {
|
@@ -106,7 +112,9 @@ class SQLite_DB {
|
|
106 |
return true;
|
107 |
} catch (PDOException $e) {
|
108 |
$this->last_error = $e->getMessage();
|
|
|
109 |
error_log("SQLite connection error: " . $e->getMessage());
|
|
|
110 |
return false;
|
111 |
}
|
112 |
}
|
@@ -139,6 +147,7 @@ class SQLite_DB {
|
|
139 |
return false;
|
140 |
} catch (PDOException $e) {
|
141 |
$this->last_error = $e->getMessage();
|
|
|
142 |
|
143 |
if (!$this->suppress_errors) {
|
144 |
if ($this->show_errors) {
|
@@ -391,7 +400,58 @@ class SQLite_DB {
|
|
391 |
}
|
392 |
|
393 |
public function check_connection($allow_bail = true) {
|
394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
}
|
396 |
|
397 |
public function db_version() {
|
|
|
31 |
class SQLite_DB {
|
32 |
public $pdo;
|
33 |
public $last_error = '';
|
34 |
+
public $error = '';
|
35 |
public $insert_id = 0;
|
36 |
public $num_rows = 0;
|
37 |
public $last_query = '';
|
|
|
69 |
$this->collate = '';
|
70 |
$this->dbname = '/var/www/html/wp-content/database';
|
71 |
$this->set_table_names();
|
72 |
+
|
73 |
+
if ($this->connect()) {
|
74 |
+
$this->ready = true;
|
75 |
+
$this->base_prefix = $this->prefix;
|
76 |
+
$this->timer_start();
|
77 |
+
} else {
|
78 |
+
$this->ready = false;
|
79 |
+
// Don't bail here, let WordPress handle the connection error
|
80 |
+
}
|
81 |
}
|
82 |
|
83 |
private function set_table_names() {
|
|
|
112 |
return true;
|
113 |
} catch (PDOException $e) {
|
114 |
$this->last_error = $e->getMessage();
|
115 |
+
$this->error = $e->getMessage();
|
116 |
error_log("SQLite connection error: " . $e->getMessage());
|
117 |
+
$this->ready = false;
|
118 |
return false;
|
119 |
}
|
120 |
}
|
|
|
147 |
return false;
|
148 |
} catch (PDOException $e) {
|
149 |
$this->last_error = $e->getMessage();
|
150 |
+
$this->error = $e->getMessage();
|
151 |
|
152 |
if (!$this->suppress_errors) {
|
153 |
if ($this->show_errors) {
|
|
|
400 |
}
|
401 |
|
402 |
public function check_connection($allow_bail = true) {
|
403 |
+
if (!$this->pdo) {
|
404 |
+
if ($allow_bail) {
|
405 |
+
$this->bail('Error establishing a database connection');
|
406 |
+
}
|
407 |
+
return false;
|
408 |
+
}
|
409 |
+
|
410 |
+
try {
|
411 |
+
// Test the connection with a simple query
|
412 |
+
$this->pdo->query('SELECT 1');
|
413 |
+
return true;
|
414 |
+
} catch (PDOException $e) {
|
415 |
+
$this->last_error = $e->getMessage();
|
416 |
+
$this->error = $e->getMessage();
|
417 |
+
|
418 |
+
if ($allow_bail) {
|
419 |
+
$this->bail('Error establishing a database connection: ' . $e->getMessage());
|
420 |
+
}
|
421 |
+
return false;
|
422 |
+
}
|
423 |
+
}
|
424 |
+
|
425 |
+
public function bail($message, $error_code = '500') {
|
426 |
+
if (!$this->show_errors) {
|
427 |
+
if (class_exists('WP_Error')) {
|
428 |
+
$this->error = new WP_Error('db_connect_fail', $message);
|
429 |
+
} else {
|
430 |
+
$this->error = $message;
|
431 |
+
}
|
432 |
+
return false;
|
433 |
+
}
|
434 |
+
|
435 |
+
if (function_exists('wp_die')) {
|
436 |
+
wp_die($message);
|
437 |
+
} else {
|
438 |
+
die($message);
|
439 |
+
}
|
440 |
+
}
|
441 |
+
|
442 |
+
public function db_connect($allow_bail = true) {
|
443 |
+
$this->ready = false;
|
444 |
+
|
445 |
+
if ($this->connect()) {
|
446 |
+
$this->ready = true;
|
447 |
+
return true;
|
448 |
+
}
|
449 |
+
|
450 |
+
if ($allow_bail) {
|
451 |
+
$this->bail('Error establishing a database connection');
|
452 |
+
}
|
453 |
+
|
454 |
+
return false;
|
455 |
}
|
456 |
|
457 |
public function db_version() {
|