public $password = null;
# Database infos
- public $title;
+ public $id;
public $name;
+ public $title;
public $type;
public $tables = [];
+ public $types = [];
+ public $conf = [];
public $row_parse; # Function to call in rows()
# Web
public $formats = [ 'table','div','csv','xml','json','yaml','sh' ];
public $limits = ['10','20','50','100','500','1000'];
+ # Classes
+ public $out;
+
function __construct($opt = '') {
# Args defaults
}
# Args into this
- foreach ($opt as $k=>$v) $this->$k = $v;
- #parent::__construct($opt);
+ #foreach ($opt as $k=>$v) $this->$k = $v;
+ parent::__construct($opt);
#if(!is_scalar($opt['type'])) debug($opt['type']);
- if (self::$encoding) out::$charset=self::$encoding;
+ if (empty($this->out)) $this->out = new Out(['charset'=>self::$encoding]);
# id
if (!empty($this->conf)) {
}
# Formats
- #$this->formats += array_keys(out::$types);
- foreach(out::$types as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
+ foreach($this->out->types() as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
# Pdo
$this->connect_init();
}
public function out($rows,$head=[]) {
- out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
+ $this->out->rows($this->p('format',$this->out->php_cli() ? 'csv' : 'table'),$rows,$head);
return true;
}
# Construct assoc array
$db = array_merge($conf[$id],array(
- 'dbs' => array_keys($conf),
+ #'dbs' => array_keys($conf),
'conf' => $conf,
'id' => $id,
));
'o' => 'format',
]);
- if ($action=self::p('action')) {
- foreach ([
+ if ($action=self::p('action')) {
+ foreach ([
- 'ls' => 'db.ls',
- 'tables' => 'db.tables',
+ 'ls' => 'db.ls',
+ 'tables' => 'db.tables',
- 'fields' => 'table.fields',
- 'rows' => 'table.rows',
- 'insert' => 'table.insert',
- 'replace' => 'table.replace',
- 'update' => 'table.update',
- 'delete' => 'table.delete',
+ 'fields' => 'table.fields',
+ 'rows' => 'table.rows',
+ 'insert' => 'table.insert',
+ 'replace' => 'table.replace',
+ 'update' => 'table.update',
+ 'delete' => 'table.delete',
- ] as $src => $dest) {
- if ($action === $src) {
- $action = $dest;
+ ] as $src => $dest) {
+ if ($action === $src) {
+ $action = $dest;
+ }
+ self::pset('action',$action);
}
- self::pset('action',$action);
}
- }
- #if($format = out::client_type()) self::pset('format',$format);
# Param - Extract dbname from table
if (false and preg_match('/^(\w+)\.(.*?)$/',self::p('table'),$m)) {
self::$type = self::client_type();
}
- public function __construct($type,&$data,$head=array()) {
- if (!empty($type) and !empty($data)) return $this->rows($type,$data,$head);
+ public function __construct($opt=[],&$data=[],$head=[]) {
+ // Statics
+ foreach ([
+ 'charset',
+ 'type',
+ ] as $k) {
+ if (isset($opt[$k])) self::${$k} = $opt[$k];
+ unset($opt[$k]);
+ }
+
+ if (isset($opt['type'])) self::$type = $opt['type'];
+ unset($opt['type']);
+
+ if (!empty(self::$type) and !empty($data)) return self::rows(self::$type,$data,$head);
+ return parent::__construct($opt);
}
+ public static function charset($set=null) { if (!empty($set)) self::$charset = $set; return self::$charset; }
+ public static function types($set=null) { if (!empty($set)) self::$types = $set; return self::$types; }
+
public static function scalar($v) {
if ($v === null) return '';
if (is_scalar($v)) return $v;