| Total Complexity | 7 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php namespace SearchReplace; |
||
| 11 | class SearchReplaceDatabase implements SearchReplaceDatabaseInterface |
||
| 12 | { |
||
| 13 | protected $db, $host, $username, $password, $database; |
||
| 14 | |||
| 15 | public function __construct($host, $username, $password, $database) |
||
| 16 | { |
||
| 17 | $this->host = $host; |
||
| 18 | $this->username = $username; |
||
| 19 | $this->password = $password; |
||
| 20 | $this->database = $database; |
||
| 21 | |||
| 22 | return $this->db(); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Return db instance |
||
| 27 | * |
||
| 28 | * @return mixed |
||
| 29 | * @throws SearchReplaceException |
||
| 30 | */ |
||
| 31 | public function db() |
||
| 32 | { |
||
| 33 | $this->db = new \mysqli($this->host, $this->username, $this->password, $this->database); |
||
| 34 | |||
| 35 | if ($this->db->connect_errno) { |
||
| 36 | throw new Exception("Failed to connect to MySQL: (" . $this->db->connect_errno . ") " . $this->db->connect_error); |
||
| 37 | } |
||
| 38 | |||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function getDatabase() |
||
| 45 | } |
||
| 46 | |||
| 47 | public function useDatabase() |
||
| 48 | { |
||
| 49 | if (empty($this->database)) |
||
| 50 | { |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | ($this->db)::select_db($this->database); |
||
| 55 | |||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get All Tables |
||
| 61 | * @return mixed |
||
| 62 | */ |
||
| 63 | public function getAllTables() |
||
| 68 | } |
||
| 69 | } |
||
| 70 |