]> git.nbdom.net Git - nb.git/commitdiff
db.id
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 8 Aug 2016 23:42:33 +0000 (01:42 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 8 Aug 2016 23:42:33 +0000 (01:42 +0200)
lib/php/db.php

index bafa3bf593d2944a35c9487a0fcc91a29bb0e7b4..bab7b46b666340fab374c5e47a36ab5388d48454 100644 (file)
@@ -11,6 +11,8 @@ require_once(realpath(dirname(__FILE__).'/out.php'));
 require_once(realpath(dirname(__FILE__).'/db/table.php'));
 require_once(realpath(dirname(__FILE__).'/db/field.php'));
 $DB_TYPES = array(); # See db/types/*.php
+#$arr = ['rent'=>'Rent','nb'=>'Nb'];
+#if (!empty($argv) and $argv[1] == 'zaza') bye($arr);
 
 class Db extends nb {
 
@@ -59,6 +61,13 @@ class Db extends nb {
     # Args
     foreach ($opt as $k=>$v) $this->$k = $v;
 
+    # id
+    if (!empty($this->conf)) {
+      foreach ($this->conf as $id=>$conf) {
+      }
+    }
+
+    # Formats
     #$this->formats += array_keys(out::$types);
     foreach(out::$types as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
 
@@ -407,7 +416,7 @@ class Db extends nb {
         } elseif ($action == 'db.dbs' or $action == 'dbs') {
           if (true or self::p('hash') or self::p('all')) {
 
-            $fields = ['name','title','type','host'];
+            $fields = ['id','name','title','type','host'];
             $dbs = [];
             $name = self::p('name','');
             $type = self::p('type','');
@@ -430,7 +439,7 @@ class Db extends nb {
             $return = $this->out($dbs,$fields);
 
           }
-          else $return = $this->out($this->dbs,"id");
+          else $return = $this->out(array_keys($this->conf),"id");
 
         } elseif ($r=self::class_action_out($this,$action) !== null) {
           return $r;
@@ -518,30 +527,31 @@ class Db extends nb {
     $Db = new self();
 
     # Load databases
-    $dbs = self::is_hash($conf) ? $conf : $Db->conf_dbs($conf);
+    $conf = self::is_hash($conf) ? $conf : $Db->conf_dbs($conf);
 
     # Check db=pdo
     if (preg_match('/^\w+:/',$Db->p('db'))) {
-      $dbs[$Db->p('db')] = array(
+      $conf[$Db->p('db')] = array(
         'pdo' => $Db->p('db'),
       );
     }
 
-    if (!$dbs) return false;
+    if (!$conf) return false;
 
     # Param - Default base on order hight num value
     if (!$Db->p('db')) {
-      $Db->pset('db',$Db->ar_first($dbs,true));
+      $Db->pset('db',$Db->ar_first($conf,true));
     }
 
-    if (!isset($dbs[$Db->p('db')])) {
-      $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
+    if (!isset($conf[$Db->p('db')])) {
+      $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($conf))."`",false);
     }
 
     # Connection
-    $db = array_merge($dbs[$Db->p('db')],array(
-      'dbs'=>array_keys($dbs),
-      'conf'=>$dbs,
+    $db = array_merge($conf[$Db->p('db')],array(
+      'dbs'=>array_keys($conf),
+      'conf'=>$conf,
+      'id'=>$Db->p('db'),
     ));
 
     $Db->__construct($db);
@@ -706,14 +716,17 @@ return;
 
     $status = $new = array();
 
-    $new = array(
-      'type' => $this->type,
+    $new = []
+    #+( empty($this->id) ? [] : ['id' => $this->id])
+    +[
+      'id' => (empty($this->id) ? '' : $this->id),
       'name' => $this->name,
+      'type' => $this->type,
       'host' => $this->host,
       #'tables' => count($this->tables()),
-      #'dbs' => count($this->dbs),
+      #'dbs' => count(array_keys($this->conf)),
       'tables' => count($this->tables()),
-    )
+    ]
     +($this->type('use_path') ? array() : array(
       'port' => $this->port,
       'user' => $this->user,