PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.5
Independent Analytics – WordPress Analytics Plugin v2.15.5
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Connectors / MySqlConnector.php
independent-analytics / vendor / illuminate / database / Connectors Last commit date
ConnectionFactory.php 1 month ago Connector.php 2 years ago ConnectorInterface.php 2 years ago MySqlConnector.php 2 years ago PostgresConnector.php 1 month ago SQLiteConnector.php 1 month ago SqlServerConnector.php 1 month ago
MySqlConnector.php
176 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Connectors;
4
5 use PDO;
6 /** @internal */
7 class MySqlConnector extends Connector implements ConnectorInterface
8 {
9 /**
10 * Establish a database connection.
11 *
12 * @param array $config
13 * @return \PDO
14 */
15 public function connect(array $config)
16 {
17 $dsn = $this->getDsn($config);
18 $options = $this->getOptions($config);
19 // We need to grab the PDO options that should be used while making the brand
20 // new connection instance. The PDO options control various aspects of the
21 // connection's behavior, and some might be specified by the developers.
22 $connection = $this->createConnection($dsn, $config, $options);
23 if (!empty($config['database'])) {
24 $connection->exec("use `{$config['database']}`;");
25 }
26 $this->configureIsolationLevel($connection, $config);
27 $this->configureEncoding($connection, $config);
28 // Next, we will check to see if a timezone has been specified in this config
29 // and if it has we will issue a statement to modify the timezone with the
30 // database. Setting this DB timezone is an optional configuration item.
31 $this->configureTimezone($connection, $config);
32 $this->setModes($connection, $config);
33 return $connection;
34 }
35 /**
36 * Set the connection transaction isolation level.
37 *
38 * @param \PDO $connection
39 * @param array $config
40 * @return void
41 */
42 protected function configureIsolationLevel($connection, array $config)
43 {
44 if (!isset($config['isolation_level'])) {
45 return;
46 }
47 $connection->prepare("SET SESSION TRANSACTION ISOLATION LEVEL {$config['isolation_level']}")->execute();
48 }
49 /**
50 * Set the connection character set and collation.
51 *
52 * @param \PDO $connection
53 * @param array $config
54 * @return void|\PDO
55 */
56 protected function configureEncoding($connection, array $config)
57 {
58 if (!isset($config['charset'])) {
59 return $connection;
60 }
61 $connection->prepare("set names '{$config['charset']}'" . $this->getCollation($config))->execute();
62 }
63 /**
64 * Get the collation for the configuration.
65 *
66 * @param array $config
67 * @return string
68 */
69 protected function getCollation(array $config)
70 {
71 return isset($config['collation']) ? " collate '{$config['collation']}'" : '';
72 }
73 /**
74 * Set the timezone on the connection.
75 *
76 * @param \PDO $connection
77 * @param array $config
78 * @return void
79 */
80 protected function configureTimezone($connection, array $config)
81 {
82 if (isset($config['timezone'])) {
83 $connection->prepare('set time_zone="' . $config['timezone'] . '"')->execute();
84 }
85 }
86 /**
87 * Create a DSN string from a configuration.
88 *
89 * Chooses socket or host/port based on the 'unix_socket' config value.
90 *
91 * @param array $config
92 * @return string
93 */
94 protected function getDsn(array $config)
95 {
96 return $this->hasSocket($config) ? $this->getSocketDsn($config) : $this->getHostDsn($config);
97 }
98 /**
99 * Determine if the given configuration array has a UNIX socket value.
100 *
101 * @param array $config
102 * @return bool
103 */
104 protected function hasSocket(array $config)
105 {
106 return isset($config['unix_socket']) && !empty($config['unix_socket']);
107 }
108 /**
109 * Get the DSN string for a socket configuration.
110 *
111 * @param array $config
112 * @return string
113 */
114 protected function getSocketDsn(array $config)
115 {
116 return "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
117 }
118 /**
119 * Get the DSN string for a host / port configuration.
120 *
121 * @param array $config
122 * @return string
123 */
124 protected function getHostDsn(array $config)
125 {
126 \extract($config, \EXTR_SKIP);
127 return isset($port) ? "mysql:host={$host};port={$port};dbname={$database}" : "mysql:host={$host};dbname={$database}";
128 }
129 /**
130 * Set the modes for the connection.
131 *
132 * @param \PDO $connection
133 * @param array $config
134 * @return void
135 */
136 protected function setModes(PDO $connection, array $config)
137 {
138 if (isset($config['modes'])) {
139 $this->setCustomModes($connection, $config);
140 } elseif (isset($config['strict'])) {
141 if ($config['strict']) {
142 $connection->prepare($this->strictMode($connection, $config))->execute();
143 } else {
144 $connection->prepare("set session sql_mode='NO_ENGINE_SUBSTITUTION'")->execute();
145 }
146 }
147 }
148 /**
149 * Set the custom modes on the connection.
150 *
151 * @param \PDO $connection
152 * @param array $config
153 * @return void
154 */
155 protected function setCustomModes(PDO $connection, array $config)
156 {
157 $modes = \implode(',', $config['modes']);
158 $connection->prepare("set session sql_mode='{$modes}'")->execute();
159 }
160 /**
161 * Get the query to enable strict mode.
162 *
163 * @param \PDO $connection
164 * @param array $config
165 * @return string
166 */
167 protected function strictMode(PDO $connection, $config)
168 {
169 $version = $config['version'] ?? $connection->getAttribute(PDO::ATTR_SERVER_VERSION);
170 if (\version_compare($version, '8.0.11') >= 0) {
171 return "set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
172 }
173 return "set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'";
174 }
175 }
176