forked from SusoGym/SEST
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySQLException.php
More file actions
35 lines (26 loc) · 809 Bytes
/
MySQLException.php
File metadata and controls
35 lines (26 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
class MySQLException extends Exception {
private $mysqli;
private $query;
/**
* MySQLException constructor.
*
* @param $mysqli mysqli
* @param $query string
*/
public function __construct($mysqli, $query) {
$message = "Error with query \"$query\": " . $mysqli->error;
$this->query = $query;
$this->mysqli = $mysqli;
parent::__construct($message);
}
public function getJson()
{
$data = array("code" => 500, "message" => "Exception", "payload" => $this->getData());
return json_encode($data, JSON_PRETTY_PRINT);
}
public function getData()
{
return array("type" => "mysql", "query" => $this->query, "message" => $this->mysqli->error);
}
}