from any database
*****************************************************************************/
-require_once(dirname(__FILE__).'/nb.php');
-require_once(dirname(__FILE__).'/out.php');
-require_once(dirname(__FILE__).'/db/table.php');
-require_once(dirname(__FILE__).'/db/field.php');
+require_once(realpath(dirname(__FILE__).'/nb.php'));
+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
class Db extends nb {
foreach(out::$types as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
# Pdo
- $this->connect();
+ $this->connect_init();
+ if (empty($this->conn)) $this->connect();
# Tables - Add missing infos
if (!empty($tables)) {
return true;
}
- function connect($pdo=null) {
-
- if ($pdo !== null) $this->pdo = $pdo;
+ function connect_init() {
if (empty($this->pdo) and $this->type) $this->pdo = $this->type.':';
if (empty($this->type)) $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$this->pdo));
if( !$this->type ) return false;
if ($this->type('use_path')) {
$this->file = preg_replace('/^\w+:/','',$this->pdo);
+ if ($p = $this->p('db.host')) $this->file = $p;
$this->host = $this->file;
} else {
# Title
if (empty($this->title)) $this->title = prettyText($this->name);
+ }
+
+ function connect() {
+
# Pdo
if (empty($this->pdo)) return false;
if (isset($this->tables)) return $this->tables;
$this->tables = array();
+#debug((array)$this->conn->query("SELECT name,type FROM sqlite_master WHERE type IN('table','view') AND name NOT LIKE 'sqlite_%' ORDER BY name",PDO::FETCH_ASSOC));
+#debug($this->type('tables',true));
foreach ($this->conn->query($this->type('tables',true),PDO::FETCH_ASSOC) as $row) {
$name = current($row);
$this->tables[$name] = $this->table($name,$row);
return true;
}
- public function action($table=null) {
+ public function action($action,$table=null) {
#if ($this->p('format') == 'table') $this->pset('format','');
- $actions = explode(',',$this->p('action'));
+# NB 20.04.16 $actions = explode(',',$this->p('action'));
+ $actions = explode(',',$action);
$this->pdef('format',($this->php_cli() ? 'csv' : ''));
$rows = array();
$return = false;
# Load databases
$dbs = self::is_hash($conf) ? $conf : $Db->conf_dbs($conf);
+
+ # Check db=pdo
+ if (preg_match('/^\w+:/',$Db->p('db'))) {
+ $dbs[$Db->p('db')] = array(
+ 'pdo' => $Db->p('db'),
+ );
+ }
+
if (!$dbs) return false;
#if (! ($dbs = $Db->conf_dbs($conf)) ) return false;
#bye($dbs['nb']);
$Db->pset('db',$Db->ar_first($dbs,true));
}
+ if (!isset($dbs[$Db->p('db')])) {
+ $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
+ }
+
# Connection
#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),
'conf'=>$dbs,
$status = $new = array();
$new = array(
- 'host' => $this->host,
- 'port' => $this->port,
+ 'type' => $this->type,
'name' => $this->name,
- 'user' => $this->user,
+ 'host' => $this->host,
#'tables' => count($this->tables()),
#'dbs' => count($this->dbs),
'tables' => count($this->tables()),
- )+$new;
+ )
+ +($this->type('use_path') ? array() : array(
+ 'port' => $this->port,
+ 'user' => $this->user,
+ ))
+ +$new;
if (($sqls=$this->type('status'))) {
<?php
-require_once(dirname(__FILE__).'/../db.php');
-require_once(dirname(__FILE__).'/../db/field.php');
-require_once(dirname(__FILE__).'/../out.php');
+require_once(realpath(dirname(__FILE__).'/../db.php'));
+require_once(realpath(dirname(__FILE__).'/../db/field.php'));
+require_once(realpath(dirname(__FILE__).'/../out.php'));
#$a = array('a','b','c'); $b = array('c','a'); debug(array_diff($a,$b));
define('TABLE_INDENT',NB_EOL ? "\t" : "");
}
// Submit
- $r .= '<input type="submit" class="button button-small" /><input type="reset" class="button button-small" />';
+ $r .= '<input type="submit" class="button button-small" value="GO"/>';
// Order By
/*