]> git.openstreetmap.org Git - nominatim.git/blob - lib/DatabaseError.php
set exception handler by request format, not always HTML
[nominatim.git] / lib / DatabaseError.php
1 <?php
2
3 namespace Nominatim;
4
5 class DatabaseError extends \Exception
6 {
7
8     public function __construct($message, $code = 500, Exception $previous = null, $oSql)
9     {
10         parent::__construct($message, $code, $previous);
11         $this->oSql = $oSql;
12     }
13
14     public function __toString()
15     {
16         return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
17     }
18
19     public function getSqlError()
20     {
21         return $this->oSql->getMessage();
22     }
23
24     public function getSqlDebugDump()
25     {
26         if (CONST_Debug) {
27             return var_export($this->oSql, true);
28         } else {
29             return $this->oSql->getUserInfo();
30         }
31     }
32 }