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 {
# 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;
} 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','');
$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;
$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);
$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,