| Total Complexity | 4 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class MysqlRunningCheck implements Check |
||
| 16 | { |
||
| 17 | const IDENTIFIER = 'base:database:mysql:running'; |
||
| 18 | |||
| 19 | private $username; |
||
| 20 | private $password; |
||
| 21 | private $host; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string $username the mysql user |
||
| 25 | * @param string $password the mysql password for the given user |
||
| 26 | * @param string $host the mysql host |
||
| 27 | */ |
||
| 28 | public function init($username, $password, $host = 'localhost') |
||
| 29 | { |
||
| 30 | $this->username = $username; |
||
| 31 | $this->password = $password; |
||
| 32 | $this->host = $host; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function run() |
||
| 36 | { |
||
| 37 | $mysqli = @(new \mysqli($this->host, $this->username, $this->password)); |
||
| 38 | |||
| 39 | if ($mysqli->connect_errno) { |
||
| 40 | $message = 'Database is not running; ' . $mysqli->connect_error; |
||
| 41 | return new Result(Result::STATUS_FAIL, $message); |
||
| 42 | } else { |
||
| 43 | return new Result(Result::STATUS_PASS, 'Mysql server is up and running.'); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getIdentifier() |
||
| 50 | } |
||
| 51 | } |
||
| 52 |