| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | public function prepare($query, $args) { |
| 14 | 14 | global $wpdb; |
| 15 | - return $wpdb->prepare($query, $args); | |
| 15 | + return $wpdb->prepare($query, $args); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function getSiteId() { |
| 19 | 19 | global $wpdb; |
| @@ -21,26 +21,40 @@ | ||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function getResult($query, $obj = ARRAY_A) { |
| 24 | 24 | global $wpdb; |
| 25 | - return $wpdb->get_results($query, $obj); | |
| 25 | + return $wpdb->get_results($query, $obj); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function query($query) { |
| 29 | 29 | global $wpdb; |
| 30 | - return $wpdb->query($query); | |
| 30 | + return $wpdb->query($query); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function getVar($query, $col = 0, $row = 0) { |
| 34 | 34 | global $wpdb; |
| 35 | - return $wpdb->get_var($query, $col, $row); | |
| 35 | + return $wpdb->get_var($query, $col, $row); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function getCol($query, $col = 0) { |
| 39 | 39 | global $wpdb; |
| 40 | - return $wpdb->get_col($query, $col); | |
| 40 | + return $wpdb->get_col($query, $col); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | + public function getAutoIncrement($table_name) { | |
| 44 | + $query = "SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table_name'"; | |
| 45 | + $results = $this->getResult($query, ARRAY_A); | |
| 46 | + $auto_increment = null; | |
| 47 | + if (empty($results)) { | |
| 48 | + return $auto_increment; | |
| 49 | + } | |
| 50 | + $row = $results[0]; | |
| 51 | + if ($row && isset($row["AUTO_INCREMENT"]) && is_numeric($row["AUTO_INCREMENT"])) { | |
| 52 | + $auto_increment = intval($row["AUTO_INCREMENT"]); | |
| 53 | + } | |
| 54 | + return $auto_increment; | |
| 55 | + } | |
| 56 | + | |
| 43 | 57 | public function tableName($table) { |
| 44 | 58 | return $table[0]; |
| 45 | 59 | } |
| 46 | 60 | |
| @@ -48,8 +62,9 @@ | ||
| 48 | 62 | $tables = $this->getResult("SHOW TABLES", ARRAY_N); |
| 49 | 63 | return array_map(array($this, 'tableName'), $tables); |
| 50 | 64 | } |
| 51 | 65 | |
| 66 | + | |
| 52 | 67 | public function showTableStatus() { |
| 53 | 68 | return $this->getResult("SHOW TABLE STATUS"); |
| 54 | 69 | } |
| 55 | 70 | |
| @@ -56,12 +71,25 @@ | ||
| 56 | 71 | public function tableKeys($table) { |
| 57 | 72 | return $this->getResult("SHOW KEYS FROM $table;"); |
| 58 | 73 | } |
| 59 | 74 | |
| 75 | + public function showDbVariables($variable) { | |
| 76 | + $variables = $this->getResult("Show variables like '%$variable%' ;"); | |
| 77 | + $result = array(); | |
| 78 | + foreach ($variables as $variable) { | |
| 79 | + $result[$variable["Variable_name"]] = $variable["Value"]; | |
| 80 | + } | |
| 81 | + return $result; | |
| 82 | + } | |
| 83 | + | |
| 60 | 84 | public function describeTable($table) { |
| 61 | 85 | return $this->getResult("DESCRIBE $table;"); |
| 62 | 86 | } |
| 63 | 87 | |
| 88 | + public function showTableIndex($table) { | |
| 89 | + return $this->getResult("SHOW INDEX FROM $table"); | |
| 90 | + } | |
| 91 | + | |
| 64 | 92 | public function checkTable($table, $type) { |
| 65 | 93 | return $this->getResult("CHECK TABLE $table $type;"); |
| 66 | 94 | } |
| 67 | 95 | |
| @@ -82,9 +110,9 @@ | ||
| 82 | 110 | $table = $this->getBVTable($name); |
| 83 | 111 | if (!$this->isTablePresent($table)) { |
| 84 | 112 | if ($usedbdelta) { |
| 85 | 113 | if (!function_exists('dbDelta')) |
| 86 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
| 114 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
| 87 | 115 | dbDelta($query); |
| 88 | 116 | } else { |
| 89 | 117 | $this->query($query); |
| 90 | 118 | } |
| @@ -151,9 +179,9 @@ | ||
| 151 | 179 | } else { |
| 152 | 180 | return false; |
| 153 | 181 | } |
| 154 | 182 | } |
| 155 | - | |
| 183 | + | |
| 156 | 184 | public function deleteBVTableContent($name, $filter = "") { |
| 157 | 185 | $table = $this->getBVTable($name); |
| 158 | 186 | if ($this->isTablePresent($table)) { |
| 159 | 187 | return $this->query("DELETE FROM $table $filter;"); |
| @@ -199,9 +227,15 @@ | ||
| 199 | 227 | global $wpdb; |
| 200 | 228 | $table = $this->getBVTable($name); |
| 201 | 229 | return $wpdb->replace($table, $value); |
| 202 | 230 | } |
| 203 | - | |
| 231 | + | |
| 232 | + public function insertIntoBVTable($name, $value) { | |
| 233 | + global $wpdb; | |
| 234 | + $table = $this->getBVTable($name); | |
| 235 | + return $wpdb->insert($table, $value); | |
| 236 | + } | |
| 237 | + | |
| 204 | 238 | public function tinfo($name) { |
| 205 | 239 | $result = array(); |
| 206 | 240 | $table = $this->getBVTable($name); |
| 207 | 241 | |
| @@ -215,9 +249,8 @@ | ||
| 215 | 249 | return $result; |
| 216 | 250 | } |
| 217 | 251 | |
| 218 | 252 | public function getMysqlVersion() { |
| 219 | - global $wpdb; | |
| 220 | - return $wpdb->db_version(); | |
| 253 | + return $this->showDbVariables('version')['version']; | |
| 221 | 254 | } |
| 222 | 255 | } |
| 223 | 256 | endif; |