| 1 |
<?php |
| 2 |
|
| 3 |
namespace ResponsiveMenu\Database; |
| 4 |
|
| 5 |
class WpDatabase implements Database { |
| 6 |
|
| 7 |
public function __construct($wpdb) { |
| 8 |
$this->db = $wpdb; |
| 9 |
} |
| 10 |
|
| 11 |
public function update($table, array $to_update, array $where) { |
| 12 |
return $this->db->update($this->db->prefix . $table, $to_update, $where); |
| 13 |
} |
| 14 |
|
| 15 |
public function delete($table, $name) { |
| 16 |
return $this->db->delete($this->db->prefix . $table, $name); |
| 17 |
} |
| 18 |
|
| 19 |
public function all($table) { |
| 20 |
return $this->db->get_results("SELECT * FROM {$this->db->prefix}{$table}"); |
| 21 |
} |
| 22 |
|
| 23 |
public function insert($table, array $arguments) { |
| 24 |
$arguments['created_at'] = current_time('mysql'); |
| 25 |
return $this->db->insert($this->db->prefix . $table, $arguments); |
| 26 |
} |
| 27 |
|
| 28 |
public function select($table, $column, $value) { |
| 29 |
return $this->db->get_results("SELECT * FROM {$this->db->prefix}{$table} WHERE $column = '$value';"); |
| 30 |
} |
| 31 |
|
| 32 |
public function mySqlTime() { |
| 33 |
return current_time('mysql'); |
| 34 |
} |
| 35 |
|
| 36 |
public function updateOption($key, $value) { |
| 37 |
return update_option($key, $value); |
| 38 |
} |
| 39 |
|
| 40 |
public function createTable($table) { |
| 41 |
$sql = "CREATE TABLE " . $this->db->prefix . $table . " ( |
| 42 |
name varchar(50) NOT NULL, |
| 43 |
value varchar(5000) DEFAULT NULL, |
| 44 |
created_at datetime NOT NULL, |
| 45 |
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 46 |
PRIMARY KEY (name) |
| 47 |
) " . $this->db->get_charset_collate() . ";"; |
| 48 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 49 |
dbDelta($sql); |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|