]> git.nbdom.net Git - nb.git/commitdiff
db.connect catch errors
authorNico Boisselier <nico@dhcp-192-168-4-150.semantico.net>
Wed, 26 Oct 2016 14:13:58 +0000 (15:13 +0100)
committerNico Boisselier <nico@dhcp-192-168-4-150.semantico.net>
Wed, 26 Oct 2016 14:13:58 +0000 (15:13 +0100)
lib/php/db.php

index 4d42b7c76ba6b781eac983db844a2d314afa385c..2b8a6274ef90157bbb9c822c2dec4522c90ea8fe 100644 (file)
@@ -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;
     }