PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / WPDB / Connection.php
ameliabooking / src / Infrastructure / DB / WPDB Last commit date
Connection.php 4 months ago Statement.php 1 week ago
Connection.php
98 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\DB\WPDB;
4
5 use AmeliaBooking\Domain\Services\Database\ConnectionInterface;
6 use wpdb;
7
8 /**
9 * Class Connection
10 *
11 * @package AmeliaBooking\Infrastructure\DB\WPDB
12 * @property \wpdb $wpdb
13 */
14 class Connection implements ConnectionInterface
15 {
16 /** @var wpdb */
17 private $wpdb;
18
19 /**
20 * @param wpdb $wpdb
21 */
22 public function __construct($wpdb)
23 {
24 $this->wpdb = $wpdb;
25
26 // Enable SQL_BIG_SELECTS to handle complex JOINs on restrictive hosting
27 $this->wpdb->query('SET SESSION SQL_BIG_SELECTS=1');
28
29 $this->wpdb->query("SET NAMES " . (defined('DB_CHARSET') ? DB_CHARSET : 'utf8mb4'));
30 }
31
32 /**
33 * @param string $statement
34 *
35 * @return Statement
36 */
37 public function query($statement)
38 {
39 $stmt = new Statement($this->wpdb, $statement);
40 $stmt->execute();
41
42 return $stmt;
43 }
44
45 /**
46 * @param string $statement
47 *
48 * @return Statement
49 */
50 public function prepare($statement)
51 {
52 return new Statement($this->wpdb, $statement);
53 }
54
55 /**
56 * @return int
57 */
58 public function lastInsertId()
59 {
60 return $this->wpdb->insert_id;
61 }
62
63 /**
64 * @return void
65 */
66 public function beginTransaction()
67 {
68 $this->wpdb->query('START TRANSACTION');
69 }
70
71 /**
72 * @return void
73 */
74 public function commit()
75 {
76 $this->wpdb->query('COMMIT');
77 }
78
79 /**
80 * @return void
81 */
82 public function rollBack()
83 {
84 $this->wpdb->query('ROLLBACK');
85 }
86
87 /**
88 * Allow the connection wrapper to be used as a callable (historical usage in repositories `$connection()`).
89 * Returning $this preserves backward compatibility without altering repository constructors.
90 *
91 * @return $this
92 */
93 public function __invoke()
94 {
95 return $this;
96 }
97 }
98