PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / Database / Exceptions / DatabaseQueryException.php

DatabaseQueryException.php in GiveWP – Donation Plugin and Fundraising Platform 2.17.0, at src/Framework/Database/Exceptions/DatabaseQueryException.php

74 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\Database\Exceptions;
4
5 use Exception;
6
7 /**
8 * Class DatabaseQueryException
9 *
10 * An exception for when errors occurred within the database while performing a query, which stores the SQL errors the
11 * database returned
12 *
13 * @since 2.9.2
14 */
15 class DatabaseQueryException extends Exception {
16 /**
17 * @var string[]
18 */
19 private $queryErrors;
20
21 /**
22 * Creates a new instance wih the query errors
23 *
24 * @since 2.9.2
25 *
26 * @param string|string[] $queryErrors
27 * @param string|null $message
28 *
29 * @return DatabaseQueryException
30 */
31 public static function create( $queryErrors, $message = null ) {
32 $error = new self();
33
34 $error->message = $message ?: 'Query failed in database';
35 $error->queryErrors = (array) $queryErrors;
36
37 return $error;
38 }
39
40 /**
41 * Returns the query errors
42 *
43 * @since 2.9.2
44 *
45 * @return string[]
46 */
47 public function getQueryErrors() {
48 return $this->queryErrors;
49 }
50
51 /**
52 * Returns a human readable form of the exception for logging
53 *
54 * @since 2.9.2
55 *
56 * @return string
57 */
58 public function getLogOutput() {
59 $queryErrors = array_map(
60 function ( $error ) {
61 return " - {$error}";
62 },
63 $this->queryErrors
64 );
65
66 return "
67 Code: {$this->getCode()}\n
68 Message: {$this->getMessage()}\n
69 DB Errors: \n
70 {$queryErrors}
71 ";
72 }
73 }
74