From: Nico Boisselier Date: Wed, 26 Oct 2016 14:13:58 +0000 (+0100) Subject: db.connect catch errors X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=d3d7714c74fe0ca8deabee785b280738f1b84966;p=nb.git db.connect catch errors --- diff --git a/lib/php/db.php b/lib/php/db.php index 4d42b7c7..2b8a6274 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -170,21 +170,20 @@ class Db extends nb { if ($p = $this->p('db.host')) $this->host = $p; # Add args to pdo - foreach (array( + foreach ([ 'host' => 'host', 'port' => 'port', 'user' => 'user', 'password' => 'password', 'name' => 'dbname', 'charset' => 'charset', - ) as $k => $v) { + ] as $k => $v) { #self::debug($k); if ($v=='charset' and $this->type=='pgsql') continue; if (empty($this->$k)) continue; $this->pdo = preg_replace("/\b$v=[^;]*(;|$)/","",$this->pdo); $this->pdo .= (preg_match('/[:;]$/',$this->pdo) ? '' : ';') . "$v=".$this->$k; } -#bye($this->pdo); } @@ -228,14 +227,14 @@ class Db extends nb { foreach(['name','host','file'] as $p) { if (!empty($this->$p)) $msg .= " $p=".$this->$p; } - $msg .= "\n".$e->getMessage(); - throw new Exception($msg, (int)$e->getCode()); + $msg .= "\n ".$e->getMessage(); + #throw new Exception($msg, (int)$e->getCode()); self::bye($msg); } #} if (empty($this->conn)) { - $this->bye("Can't connect to: ".$this->pdo_info($this->pdo)); + $this->bye("Connection failed: ".$this->pdo_info($this->pdo)); return false; }