QueryBuilder
4 years ago
DbInfo.php
3 years ago
ExcludedTables.php
4 years ago
SearchReplace.php
3 years ago
SelectedTables.php
2 years ago
TableDto.php
5 years ago
TableService.php
3 years ago
TablesRenamer.php
2 years ago
WpDbInfo.php
5 years ago
iDbInfo.php
5 years ago
DbInfo.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Database; |
| 4 | |
| 5 | class DbInfo extends WpDbInfo |
| 6 | { |
| 7 | /* |
| 8 | * @var string |
| 9 | */ |
| 10 | protected $server; |
| 11 | |
| 12 | /* |
| 13 | * @var string |
| 14 | */ |
| 15 | protected $user; |
| 16 | |
| 17 | /* |
| 18 | * @var string |
| 19 | */ |
| 20 | protected $password; |
| 21 | |
| 22 | /* |
| 23 | * @var string |
| 24 | */ |
| 25 | protected $database; |
| 26 | |
| 27 | /* |
| 28 | * @var string|null |
| 29 | */ |
| 30 | protected $error; |
| 31 | |
| 32 | /* |
| 33 | * @var bool |
| 34 | */ |
| 35 | protected $connected; |
| 36 | |
| 37 | /* |
| 38 | * @var bool |
| 39 | */ |
| 40 | protected $useSsl; |
| 41 | |
| 42 | /* |
| 43 | * @param string $hostServer |
| 44 | * @param string $user |
| 45 | * @param string $password |
| 46 | * @param string $database |
| 47 | * @param bool $useSsl |
| 48 | */ |
| 49 | public function __construct($hostServer, $user, $password, $database, $useSsl = false) |
| 50 | { |
| 51 | $this->server = $hostServer; |
| 52 | $this->user = $user; |
| 53 | $this->password = $password; |
| 54 | $this->database = $database; |
| 55 | $this->useSsl = $useSsl; |
| 56 | |
| 57 | parent::__construct($this->connect()); |
| 58 | } |
| 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 | $this->error = null; |
| 76 | $this->connected = true; |
| 77 | if ($db->connect_error) { |
| 78 | $this->error = 'Connect Error (' . $db->connect_errno . ') ' . $db->connect_error; |
| 79 | $this->connected = false; |
| 80 | return; |
| 81 | } |
| 82 | $db->close(); |
| 83 | |
| 84 | $wpdb = new \wpdb($this->user, $this->password, $this->database, $this->server); |
| 85 | return $wpdb; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * @return string|null |
| 90 | */ |
| 91 | public function getError() |
| 92 | { |
| 93 | return $this->error; |
| 94 | } |
| 95 | } |
| 96 |