PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.2
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.2
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / vendor / wpfluent / framework / src / WPFluent / Database / QueryException.php

QueryException.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.4.2, at vendor/wpfluent/framework/src/WPFluent/Database/QueryException.php

99 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\Framework\Database;
4
5 use PDOException;
6
7 class QueryException extends PDOException
8 {
9
10 /**
11 * The SQL for the query.
12 *
13 * @var string
14 */
15 protected $sql;
16
17 /**
18 * The bindings for the query.
19 *
20 * @var array
21 */
22 protected $bindings;
23
24 /**
25 * Create a new query exception instance.
26 *
27 * @param string $sql
28 * @param array $bindings
29 * @param \Exception $previous
30 * @return void
31 */
32 public function __construct($sql, array $bindings, $previous)
33 {
34 parent::__construct('', 0, $previous);
35
36 $this->sql = $sql;
37 $this->bindings = $bindings;
38 $this->previous = $previous;
39 $this->code = $previous->getCode();
40 $this->message = $this->formatMessage($sql, $bindings, $previous);
41
42 if ($previous instanceof PDOException) {
43 $this->errorInfo = $previous->errorInfo;
44 }
45 }
46
47 /**
48 * Format the SQL error message.
49 *
50 * @param string $sql
51 * @param array $bindings
52 * @param \Exception $previous
53 * @return string
54 */
55 protected function formatMessage($sql, $bindings, $previous)
56 {
57 $message = $this->strReplaceArray('\?', $bindings, $sql);
58
59 return $previous->getMessage() . ' (SQL: ' . $message . ')';
60 }
61
62 /**
63 * Get the SQL for the query.
64 *
65 * @return string
66 */
67 public function getSql()
68 {
69 return $this->sql;
70 }
71
72 /**
73 * Get the bindings for the query.
74 *
75 * @return array
76 */
77 public function getBindings()
78 {
79 return $this->bindings;
80 }
81
82 /**
83 * Replace placeholders with bindings
84 *
85 * @param string $search
86 * @param array $replace
87 * @param string $subject
88 * @return string $subject
89 */
90 protected function strReplaceArray($search, array $replace, $subject)
91 {
92 foreach ($replace as $value) {
93 $subject = preg_replace('/' . $search . '/', $value, $subject, 1);
94 }
95
96 return $subject;
97 }
98 }
99