PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / IncrementalBackup / Database / MysqlConnection.php

MysqlConnection.php in ManageWP Worker 4.9.25, at src/MWP/IncrementalBackup/Database/MysqlConnection.php

83 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <contact@managewp.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_IncrementalBackup_Database_MysqlConnection implements MWP_IncrementalBackup_Database_ConnectionInterface
12 {
13
14 /**
15 * @var resource
16 */
17 private $connection;
18
19 /**
20 * @var
21 */
22 private $configuration;
23
24 public function __construct(MWP_IncrementalBackup_Database_Configuration $configuration)
25 {
26 $this->configuration = $configuration;
27
28 if (!extension_loaded('mysql')) {
29 throw new MWP_IncrementalBackup_Database_Exception_ConnectionException("Mysql extension is not loaded.");
30 }
31
32 if ($configuration->isSocket()) {
33 /** @handled function */
34 $this->connection = @mysql_connect(':'.$configuration->getSocketPath(), $configuration->getUsername(), $configuration->getPassword());
35 } else {
36 $host = $configuration->getHost();
37 if ($configuration->getPort() !== null) {
38 $host .= ':'.$configuration->getPort();
39 }
40 /** @handled function */
41 $this->connection = @mysql_connect($host, $configuration->getUsername(), $configuration->getPassword());
42 }
43
44 if (!is_resource($this->connection)) {
45 throw new MWP_IncrementalBackup_Database_Exception_ConnectionException(mysql_error(), mysql_errno());
46 }
47 /** @handled function */
48 @mysql_set_charset($configuration->getCharset(), $this->connection);
49 /** @handled function */
50 mysql_select_db($configuration->getDatabase(), $this->connection);
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 public function query($query, $useResult = false)
57 {
58 if ($useResult) {
59 /** @handled function */
60 $result = mysql_unbuffered_query($query, $this->connection);
61 } else {
62 /** @handled function */
63 $result = mysql_query($query, $this->connection);
64 }
65
66 if ($result === false) {
67 throw new MWP_IncrementalBackup_Database_Exception_ConnectionException(mysql_error($this->connection), mysql_errno($this->connection));
68 }
69
70 return new MWP_IncrementalBackup_Database_MysqlStatement($result);
71 }
72
73 /**
74 * @param mixed $value any primitive value
75 *
76 * @return string
77 */
78 public function quote($value)
79 {
80 return "'".mysql_real_escape_string($value, $this->connection)."'";
81 }
82 }
83