PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.0
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 / DbInfo.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 WpOptionsInfo.php 2 years ago iDbInfo.php 2 years ago
DbInfo.php
85 lines
1 <?php
2
3 namespace WPStaging\Framework\Database;
4
5 use Exception;
6 use mysqli;
7 use wpdb;
8 use WPStaging\Framework\Adapter\Database\DatabaseException;
9
10 class DbInfo extends WpDbInfo
11 {
12 /**
13 * @var string
14 */
15 protected $server;
16
17 /**
18 * @var string
19 */
20 protected $user;
21
22 /**
23 * @var string
24 */
25 protected $password;
26
27 /**
28 * @var string
29 */
30 protected $database;
31
32 /**
33 * @var bool
34 */
35 protected $useSsl;
36
37 /**
38 * @param string $hostServer
39 * @param string $user
40 * @param string $password
41 * @param string $database
42 * @param bool $useSsl
43 * @throws DatabaseException
44 */
45 public function __construct(string $hostServer, string $user, string $password, string $database, bool $useSsl = false)
46 {
47 $this->server = $hostServer;
48 $this->user = $user;
49 $this->password = $password;
50 $this->database = $database;
51 $this->useSsl = $useSsl;
52
53 parent::__construct($this->connect());
54 }
55
56 /**
57 * @return wpdb
58 * @throws DatabaseException
59 */
60 public function connect()
61 {
62 if ($this->useSsl) {
63 // wpdb requires this constant for SSL use
64 if (!defined('MYSQL_CLIENT_FLAGS')) {
65 // phpcs:disable PHPCompatibility.Constants.NewConstants.mysqli_client_ssl_dont_verify_server_certFound
66 define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
67 }
68
69 $db = mysqli_init();
70 $db->real_connect($this->server, $this->user, $this->password, $this->database, null, null, MYSQL_CLIENT_FLAGS);
71 } else {
72 $db = new mysqli($this->server, $this->user, $this->password, $this->database);
73 }
74
75 if ($db->connect_error) {
76 throw new DatabaseException('Connect Error (' . $db->connect_errno . ') ' . $db->connect_error);
77 }
78
79 $db->close();
80
81 $wpdb = new wpdb($this->user, $this->password, $this->database, $this->server);
82 return $wpdb;
83 }
84 }
85