1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Core\Database\Connections; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class MySqlConnector |
7
|
|
|
* @package Coco\SourceWatcher\Core\Database\Connections |
8
|
|
|
* |
9
|
|
|
* Following the definition from: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#pdo-mysql |
10
|
|
|
*/ |
11
|
|
|
class MySqlConnector extends ClientServerDatabaseConnector |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected string $unixSocket = ""; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected string $charset = ""; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* MySqlConnector constructor. |
25
|
|
|
*/ |
26
|
|
|
public function __construct () |
27
|
|
|
{ |
28
|
|
|
$this->driver = "pdo_mysql"; |
29
|
|
|
|
30
|
|
|
$this->port = 3306; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public function getUnixSocket () : string |
37
|
|
|
{ |
38
|
|
|
return $this->unixSocket; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $unixSocket |
43
|
|
|
*/ |
44
|
|
|
public function setUnixSocket ( string $unixSocket ) : void |
45
|
|
|
{ |
46
|
|
|
$this->unixSocket = $unixSocket; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getCharset () : string |
53
|
|
|
{ |
54
|
|
|
return $this->charset; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $charset |
59
|
|
|
*/ |
60
|
|
|
public function setCharset ( string $charset ) : void |
61
|
|
|
{ |
62
|
|
|
$this->charset = $charset; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function getConnectionParameters () : array |
69
|
|
|
{ |
70
|
|
|
$this->connectionParameters = array(); |
71
|
|
|
|
72
|
|
|
$this->connectionParameters["driver"] = $this->driver; |
73
|
|
|
$this->connectionParameters["user"] = $this->user; |
74
|
|
|
$this->connectionParameters["password"] = $this->password; |
75
|
|
|
$this->connectionParameters["host"] = $this->host; |
76
|
|
|
$this->connectionParameters["port"] = $this->port; |
77
|
|
|
$this->connectionParameters["dbname"] = $this->dbName; |
78
|
|
|
|
79
|
|
|
if ( isset( $this->unixSocket ) && $this->unixSocket !== "" ) { |
80
|
|
|
$this->connectionParameters["unix_socket"] = $this->unixSocket; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ( isset( $this->charset ) && $this->charset !== "" ) { |
84
|
|
|
$this->connectionParameters["charset"] = $this->charset; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->connectionParameters; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|