From 9fa6f8d0bfae31c780ab74d44aa590f41e885312 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 9 Aug 2016 01:42:33 +0200 Subject: [PATCH] db.id --- lib/php/db.php | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index bafa3bf5..bab7b46b 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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, -- 2.47.3