PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.3.1
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.3.1
4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Database / WpDbInfo.php
wp-staging / Framework / Database Last commit date
QueryBuilder 2 years ago DbInfo.php 2 years ago ExcludedTables.php 4 years ago OptionPreservationHandler.php 2 years ago SearchReplace.php 2 years ago SelectedTables.php 2 years ago TableDto.php 5 years ago TableService.php 2 years ago TablesRenamer.php 2 years ago WpDbInfo.php 2 years ago iDbInfo.php 2 years ago
WpDbInfo.php
107 lines
1 <?php
2
3 namespace WPStaging\Framework\Database;
4
5 class WpDbInfo implements iDbInfo
6 {
7 /**
8 * @var \wpdb
9 */
10 protected $wpdb;
11
12 /**
13 * @param \wpdb $wpdb
14 */
15 public function __construct($wpdb)
16 {
17 $this->wpdb = $wpdb;
18 }
19
20 /**
21 * Get the database default collation: collation_database
22 * @return string
23 */
24 public function getDbCollation(): string
25 {
26 $result = $this->wpdb->dbh->query("SHOW VARIABLES LIKE 'collation_database'");
27
28 $output = '';
29 if ($obj = $result->fetch_object()) {
30 $output = $obj->Value;
31 }
32
33 return $output;
34 }
35
36 /**
37 * @return string
38 */
39 public function getDbEngine(): string
40 {
41 $result = $this->wpdb->dbh->query("SHOW VARIABLES LIKE 'default_storage_engine'");
42
43 $output = '';
44 if ($obj = $result->fetch_object()) {
45 $output = $obj->Value;
46 }
47
48 return $output;
49 }
50
51 /**
52 * @return int
53 */
54 public function getMySqlServerVersion(): int
55 {
56 return $this->wpdb->dbh->server_version;
57 }
58
59 /**
60 * @return int
61 */
62 public function getMySqlClientVersion(): int
63 {
64 return $this->wpdb->dbh->client_version;
65 }
66
67 /**
68 * @return string
69 */
70 public function getServerIp(): string
71 {
72 $queryToFindHost = "SHOW VARIABLES WHERE Variable_name = 'hostname';";
73 return $this->wpdb->get_var($queryToFindHost, 1);
74 }
75
76 /**
77 * @return int
78 */
79 public function getServerPort(): int
80 {
81 $queryToFindPort = "SHOW VARIABLES WHERE Variable_name = 'port';";
82 return (int)$this->wpdb->get_var($queryToFindPort, 1);
83 }
84
85 /**
86 * Return the server name and port as server:port
87 * @return string
88 */
89 public function getServer(): string
90 {
91 return $this->getServerIp() . ':' . $this->getServerPort();
92 }
93
94 /**
95 * @return array
96 */
97 public function toArray(): array
98 {
99 return [
100 'db_engine' => $this->getDbEngine(),
101 'db_collation' => $this->getDbCollation(),
102 'db_server_ver' => $this->getMySqlServerVersion(),
103 'db_client_ver' => $this->getMySqlClientVersion()
104 ];
105 }
106 }
107