| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared | |
| 2 | + | |
| 3 | 3 | if (!defined('ABSPATH')) exit; |
| 4 | 4 | if (!class_exists('WPRWPDb')) : |
| 5 | 5 | |
| 6 | 6 | class WPRWPDb { |
| @@ -39,23 +39,8 @@ | ||
| 39 | 39 | global $wpdb; |
| 40 | 40 | return $wpdb->get_col($query, $col); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function getLastRowId($col_name, $table_name) { | |
| 44 | - $query = "SELECT MAX($col_name) AS last_id FROM $table_name"; | |
| 45 | - $results = $this->getResult($query); | |
| 46 | - if (empty($results) || !is_array($results) || !is_array($results[0]) || | |
| 47 | - !array_key_exists("last_id", $results[0])) { | |
| 48 | - return null; | |
| 49 | - } | |
| 50 | - $last_id = $results[0]['last_id']; | |
| 51 | - if ($last_id === null) { | |
| 52 | - return 0; | |
| 53 | - } else if (is_numeric($last_id) === true) { | |
| 54 | - return (int) $last_id; | |
| 55 | - } | |
| 56 | - } | |
| 57 | - | |
| 58 | 43 | public function tableName($table) { |
| 59 | 44 | return $table[0]; |
| 60 | 45 | } |
| 61 | 46 | |
| @@ -63,9 +48,8 @@ | ||
| 63 | 48 | $tables = $this->getResult("SHOW TABLES", ARRAY_N); |
| 64 | 49 | return array_map(array($this, 'tableName'), $tables); |
| 65 | 50 | } |
| 66 | 51 | |
| 67 | - | |
| 68 | 52 | public function showTableStatus() { |
| 69 | 53 | return $this->getResult("SHOW TABLE STATUS"); |
| 70 | 54 | } |
| 71 | 55 | |
| @@ -72,25 +56,12 @@ | ||
| 72 | 56 | public function tableKeys($table) { |
| 73 | 57 | return $this->getResult("SHOW KEYS FROM $table;"); |
| 74 | 58 | } |
| 75 | 59 | |
| 76 | - public function showDbVariables($variable) { | |
| 77 | - $variables = $this->getResult("Show variables like '%$variable%' ;"); | |
| 78 | - $result = array(); | |
| 79 | - foreach ($variables as $variable) { | |
| 80 | - $result[$variable["Variable_name"]] = $variable["Value"]; | |
| 81 | - } | |
| 82 | - return $result; | |
| 83 | - } | |
| 84 | - | |
| 85 | 60 | public function describeTable($table) { |
| 86 | 61 | return $this->getResult("DESCRIBE $table;"); |
| 87 | 62 | } |
| 88 | 63 | |
| 89 | - public function showTableIndex($table) { | |
| 90 | - return $this->getResult("SHOW INDEX FROM $table"); | |
| 91 | - } | |
| 92 | - | |
| 93 | 64 | public function checkTable($table, $type) { |
| 94 | 65 | return $this->getResult("CHECK TABLE $table $type;"); |
| 95 | 66 | } |
| 96 | 67 | |
| @@ -111,9 +82,9 @@ | ||
| 111 | 82 | $table = $this->getBVTable($name); |
| 112 | 83 | if (!$this->isTablePresent($table)) { |
| 113 | 84 | if ($usedbdelta) { |
| 114 | 85 | if (!function_exists('dbDelta')) |
| 115 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
| 86 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
| 116 | 87 | dbDelta($query); |
| 117 | 88 | } else { |
| 118 | 89 | $this->query($query); |
| 119 | 90 | } |
| @@ -180,9 +151,9 @@ | ||
| 180 | 151 | } else { |
| 181 | 152 | return false; |
| 182 | 153 | } |
| 183 | 154 | } |
| 184 | - | |
| 155 | + | |
| 185 | 156 | public function deleteBVTableContent($name, $filter = "") { |
| 186 | 157 | $table = $this->getBVTable($name); |
| 187 | 158 | if ($this->isTablePresent($table)) { |
| 188 | 159 | return $this->query("DELETE FROM $table $filter;"); |
| @@ -228,15 +199,9 @@ | ||
| 228 | 199 | global $wpdb; |
| 229 | 200 | $table = $this->getBVTable($name); |
| 230 | 201 | return $wpdb->replace($table, $value); |
| 231 | 202 | } |
| 232 | - | |
| 233 | - public function insertIntoBVTable($name, $value) { | |
| 234 | - global $wpdb; | |
| 235 | - $table = $this->getBVTable($name); | |
| 236 | - return $wpdb->insert($table, $value); | |
| 237 | - } | |
| 238 | - | |
| 203 | + | |
| 239 | 204 | public function tinfo($name) { |
| 240 | 205 | $result = array(); |
| 241 | 206 | $table = $this->getBVTable($name); |
| 242 | 207 | |
| @@ -250,8 +215,9 @@ | ||
| 250 | 215 | return $result; |
| 251 | 216 | } |
| 252 | 217 | |
| 253 | 218 | public function getMysqlVersion() { |
| 254 | - return $this->showDbVariables('version')['version']; | |
| 219 | + global $wpdb; | |
| 220 | + return $wpdb->db_version(); | |
| 255 | 221 | } |
| 256 | 222 | } |
| 257 | 223 | endif; |