|
1
|
|
|
<?php |
|
2
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
3
|
|
|
namespace SetBased\Audit\MySql\Command; |
|
4
|
|
|
|
|
5
|
|
|
use SetBased\Audit\Command\BaseCommand; |
|
6
|
|
|
use SetBased\Audit\MySql\AuditDataLayer; |
|
7
|
|
|
|
|
8
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
9
|
|
|
/** |
|
10
|
|
|
* Base class for commands which needs to connect to a MySQL instance. |
|
11
|
|
|
*/ |
|
12
|
|
|
class MySqlBaseCommand extends BaseCommand |
|
13
|
|
|
{ |
|
14
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
15
|
|
|
/** |
|
16
|
|
|
* Disconnects from MySQL instance. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function disconnect() |
|
19
|
|
|
{ |
|
20
|
|
|
AuditDataLayer::disconnect(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
24
|
|
|
/** |
|
25
|
|
|
* Connects to a MySQL instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $settings The settings from the configuration file. |
|
28
|
|
|
*/ |
|
29
|
9 |
|
protected function connect($settings) |
|
30
|
|
|
{ |
|
31
|
9 |
|
$host = $this->getSetting($settings, true, 'database', 'host'); |
|
32
|
9 |
|
$user = $this->getSetting($settings, true, 'database', 'user'); |
|
33
|
9 |
|
$password = $this->getSetting($settings, true, 'database', 'password'); |
|
34
|
9 |
|
$database = $this->getSetting($settings, true, 'database', 'data_schema'); |
|
35
|
|
|
|
|
36
|
9 |
|
AuditDataLayer::setIo($this->io); |
|
37
|
9 |
|
AuditDataLayer::connect($host, $user, $password, $database); |
|
38
|
9 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
44
|
|
|
|