PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / DB / MySQLi / Connection.php
ameliabooking / src / Infrastructure / DB / MySQLi Last commit date
Connection.php 2 years ago Query.php 7 years ago Result.php 7 years ago Statement.php 4 years ago
Connection.php
153 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\DB\MySQLi;
4
5 use AmeliaBooking\Domain\Services\Settings\SettingsService;
6 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
7 use mysqli;
8
9 /**
10 * Class Connection
11 *
12 * @package AmeliaBooking\Infrastructure\DB\MySQLi
13 */
14 class Connection extends \AmeliaBooking\Infrastructure\Connection
15 {
16 /** @var Statement $statement */
17 public $statement;
18
19 /** @var Result $result */
20 private $result;
21
22 /** @var Query $query */
23 private $query;
24
25 /** @var mysqli $mysqli */
26 private $mysqli;
27
28 /**
29 * Connection constructor.
30 *
31 * @param string $database
32 * @param string $username
33 * @param string $password
34 * @param string $host
35 * @param int $port
36 * @param string $charset
37 */
38 public function __construct(
39 $host,
40 $database,
41 $username,
42 $password,
43 $charset = 'utf8',
44 $port = 3306
45 ) {
46 parent::__construct(
47 $host,
48 $database,
49 $username,
50 $password,
51 $charset,
52 $port
53 );
54
55 $this->socketHandler();
56
57 $this->result = new Result();
58
59 $this->query = new Query();
60
61 if (property_exists($this, 'socketPath') && $this->socketPath) {
62 $this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->database, $this->port, $this->socketPath);
63 } else {
64 $this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->database, $this->port);
65 }
66
67 $settingsService = new SettingsService(new SettingsStorage());
68
69 $ssl = apply_filters('amelia_change_ssl_settings', $settingsService->getSetting('db', 'ssl'));
70
71 if ($ssl['enable']) {
72 $this->mysqli->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], null, null);
73 }
74
75 $this->mysqli->set_charset($this->charset);
76
77 $stmt = $this->mysqli->prepare('SET SESSION sql_mode = "TRADITIONAL"');
78 $stmt->execute();
79
80 $stmt = $this->mysqli->prepare('SET FOREIGN_KEY_CHECKS = 0');
81 $stmt->execute();
82
83 $settingsService = new SettingsService(new SettingsStorage());
84
85 if ($settingsService->getSetting('db', 'pdoBigSelect')) {
86 $stmt = $this->mysqli->prepare('SET SQL_BIG_SELECTS = 1');
87 $stmt->execute();
88 }
89
90 $this->statement = new Statement($this->mysqli, $this->result, $this->query);
91
92 $this->handler = $this;
93 }
94
95 /**
96 * @param string $query
97 *
98 * @return mixed
99 */
100 public function query($query)
101 {
102 $this->result->setValue($this->mysqli->query($query));
103
104 return $this->statement;
105 }
106
107 /**
108 * @param string $query
109 *
110 * @return mixed
111 */
112 public function prepare($query)
113 {
114 $this->query->setValue($query);
115
116 return $this->statement;
117 }
118
119 /**
120 *
121 * @return string|false
122 */
123 public function lastInsertId()
124 {
125 return $this->mysqli->insert_id;
126 }
127
128 /**
129 *
130 * @return mixed
131 */
132 public function beginTransaction()
133 {
134 return $this->mysqli->begin_transaction();
135 }
136
137 /**
138 * @return bool
139 */
140 public function commit()
141 {
142 return $this->mysqli->commit();
143 }
144
145 /**
146 * @return bool
147 */
148 public function rollback()
149 {
150 return $this->mysqli->rollback();
151 }
152 }
153