pdo: 'sqlite:/dev/shm/crypt.db'
puppetdb:
- pdo: 'pgsql:host=big;dbname=puppetdb;user=puppetdb;password='
+ #pdo: 'pgsql:host=big;dbname=puppetdb;user=puppetdb;password='
title: Puppetdb
+ host: big
+ type: pgsql
+ name: puppetdb
+ user: puppetdb
default_table: view_hosts
tables:
hosts:
type: "int"
extra: 1
izi:
- pdo: 'mysql:host=admin.izideal.com;port=3306;dbname=izi'
- username: izideal
+ #pdo: 'mysql:host=admin.izideal.com;port=3306;dbname=izi'
title: Mysql Izi on Admin
+ default_table: process
+
+ user: izideal
+ type: mysql
+ host: admin.izideal.com
+ name: izi
options:
- "PDO::MYSQL_ATTR_INIT_COMMAND: SET NAMES utf8'"
- default_table: process
izidev:
- pdo: 'mysql:host=big.cascais.loc;port=3306;dbname=izi'
- username: nico
+ #pdo: 'mysql:host=big.cascais.loc;port=3306;dbname=izi'
title: Mysql Izi on Big
+ default_table: process
+
+ user: nico
+ type: mysql
+ host: admin.izideal.com
+ name: izi
options:
- "PDO::MYSQL_ATTR_INIT_COMMAND: SET NAMES utf8'"
- default_table: process
ui:
pdo: 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db'
# NB 10.01.16 template:
# NB 10.01.16 View: "'<a href=\"/template/'||id||'\">'||id||'</a>'"
postfix:
- pdo: 'mysql:host=media.izideal.vpn;port=3306;dbname=postfix'
- username: postfix
+ #pdo: 'mysql:host=media.izideal.vpn;port=3306;dbname=postfix'
+ user: postfix
title: Postfix on Izideal
+
+ type: mysql
+ host: media.izideal.vpn
+ name: postfix
options:
- "PDO::MYSQL_ATTR_INIT_COMMAND: SET NAMES utf8'"
# PDO Connection
public $conn;
public $pdo;
+ public $pdo_error = PDO::ERRMODE_EXCEPTION; # See: http://php.net/manual/en/pdo.error-handling.php
public $options;
- public $username = null;
+ public $host = null;
+ public $port = null;
+ public $user = null;
public $password = null;
- public $pdo_error = PDO::ERRMODE_EXCEPTION; # See: http://php.net/manual/en/pdo.error-handling.php
# Database infos
public $title;
# Args
$db = is_scalar($db) ? array('pdo' => $db) : $db;
if (is_array($db)) {
-
-# NB 05.03.16 if (!empty($db->configs)) {
-# NB 05.03.16 $this->dbs = $this->config2h($db->dbs);
-# NB 05.03.16 unset($db->dbs);
-# NB 05.03.16 }
-
foreach ($db as $k=>$v) $this->$k = $v;
}
function connect($pdo=null) {
if ($pdo !== null) $this->pdo = $pdo;
+ if (empty($this->pdo) and $this->type) $this->pdo = $this->type.':';
+ if (empty($this->type)) $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$this->pdo));
+
+ # Title
+ if (empty($this->title)) $this->title = prettyText($this->name);
# Name
- #if (empty($this->name)) $this->name = preg_replace('/^(?:(?:sqlite:.*(.*?)(\.\w+)?)|(?:.*?dbname=([^;]+).*?))$/','\1',$this->pdo);
-# NB 22.12.15 if (empty($this->name) and preg_match('/(?:sqlite:|dbname=)([^;\.]+)/',$this->pdo,$m)) {
- if (empty($this->name) and !empty($this->pdo)
- and preg_match('/(?:sqlite:(?:.*\/)?|dbname=)([^;\.]+)/',$this->pdo,$m)
- ) {
+ if (empty($this->name) and preg_match('/(?:sqlite:(?:.*\/)?|dbname=)([^;\.]+)/',$this->pdo,$m)) {
$this->name = $m[1];
}
- # Title
- if (empty($this->title)) $this->title = prettyText($this->name);
+ # User
+ #preg_match_all('/[:;](user|username|password)=([^;]*)/',$this->pdo,$m); bye($m);
+
+ # Params
+ if (preg_match_all("/[:;](\w+)=([^;]+)/",$this->pdo,$m,PREG_SET_ORDER)) {
+ #array_shift($m);
+ foreach ($m as $param) {
+ $k = $param[1];
+ if (!empty($this->$k)) continue;
+ $this->$k = $param[2];
+ }
+ #$this->bye($m);
+ }
+ #$this->bye($this->pdo);
+
+ if ($this->type != 'sqlite') {
+ foreach (array(
+ 'host' => 'host',
+ 'port' => 'port',
+ 'user' => 'user',
+ 'password' => 'password',
+ 'name' => 'dbname',
+ ) as $k => $v) {
+ #self::debug($k);
+ if (empty($this->$k)) continue;
+ $this->pdo = preg_replace("/\b$v=[^;]*(;|$)/","",$this->pdo);
+ $this->pdo .= (preg_match('/[:;]$/',$this->pdo) ? '' : ';') . "$v=".$this->$k;
+ }
+ }
+ #self::bye(">>".$this->pdo);
+
+ # Pdo
if (empty($this->pdo)) return false;
# Type
- $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$this->pdo));
if (!in_array($this->type,array(
'sqlite',
'mysql',
'pgsql',
))) $this->bye("unknow type = `".$this->type."`");
- # User
- #preg_match_all('/[:;](user|username|password)=([^;]*)/',$this->pdo,$m); bye($m);
-
# Connect
if (preg_match('/^sqlite:(.*)$/',$this->pdo,$m) and !is_readable($m[1])) {
$this->bye("Can't connect to database `".$m[1]."` type=$this->type",false);
} else {
- $this->conn = new PDO($this->pdo,$this->username,$this->password,$this->options);
+ $this->conn = new PDO($this->pdo,$this->user,$this->password,$this->options);
+
+ if ($this->type == 'pgsql') {
+ if (isset($this->password)) $this->pdo = preg_replace('/\bpassword=([^;]+;?)/','',$this->pdo).'';
+ }
if (isset($this->pdo_error)) $this->conn->setAttribute(PDO::ATTR_ERRMODE, $this->pdo_error);
}
if (!empty($files)) {
- if (empty($h)) $h = array();
+ $h = array();
foreach ($files as $file) {
if (is_readable($file) and ($yaml = @yaml_parse_file($file))) {
#foreach ($yaml as $k=>$v) { $yaml[$k]['_config2h'] = $file; }
+ #debug($file);
$h = array_replace_recursive($h,$yaml);
}
#debug($file);
#debug($h);
}
if (!$h) return false;
+ #self::bye($h['puppetdb']);
#if ($first !== false) debug ( self::ar_first($h) );
if ($first !== false) $first = self::ar_first($h);
return $h;
$Db = new self();
#bye($_SERVER["PHP_SELF"]); bye($_SERVER);
- if (!array_key_exists(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml';
- if (!array_key_exists('/etc/rent/db.yaml',$conf)) $conf[] = '/etc/rent/db.yaml';
- if (!array_key_exists('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml';
+ if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml';
+ if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml';
# Load databases
if (! ($dbs = $Db->config2h($conf)) ) return false;
# NB 05.03.16 #$ar[] = 'b';
# NB 05.03.16 array_unshift($ar,'b');
# NB 05.03.16 bye($ar);
-# NB 05.03.16 bye($dbs['puppetdb']);
+ #bye($dbs['izi']);
# Param - Extract dbname from table
if (preg_match('/^(\w+)\.(.*?)$/',$Db->p('table'),$m)) {
#bye($Db->p('db'));
if (!isset($dbs[$Db->p('db')])) $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
$db = array_merge($dbs[$Db->p('db')],array('dbs'=>array_keys($dbs)));
+ unset($dbs);
- if (empty($db['pdo'])) $Db->bye("No pdo for db: `".$Db->p('db')."`",false);
-
- #bye($db['pdo']);
$Db->__construct($db);
- unset($dbs);
+ if (empty($Db->pdo)) $Db->bye("No pdo for db: `".$Db->p('db')."`",false);
/*
Table