From: Nicolas Boisselier Date: Mon, 5 Dec 2016 10:25:03 +0000 (+0000) Subject: fix bug db.tables X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=97e8826cf9a2cef19e535d36b5f1e01254469099;p=nb.git fix bug db.tables --- diff --git a/lib/php/db.php b/lib/php/db.php index 4c9c7443..9f6f7aaf 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -383,8 +383,9 @@ class Db extends nb { if (!$name and !empty($this->default_table)) $name = $this->default_table; if (!$name) bye('table name is empty'); + if (empty($params) or empty($params['db'])) $params['db'] = $this; if (empty($this->tables[$name])) { - $this->tables[$name] = new Table($name,['db'=>$this]+$params); + $this->tables[$name] = new Table($name,$params); } elseif ($params) { $this->tables[$name]->__construct($name,$params); } @@ -403,7 +404,6 @@ class Db extends nb { $return = []; foreach (explode("\n",file_get_contents($config[0])) as $line) { -#bye($line); if (!preg_match('/'.($config[1]).'/',$line,$m)) continue; foreach ($m as $k=>$v) if (preg_match('/^\d+$/',$k)) unset($m[$k]); $return = array_replace_recursive($return,$m); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index fdcca9a4..5294cded 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -124,6 +124,7 @@ Class Table extends nb { */ public function db($set=null) { static $db = null; + #if ($set !== null) debug($set->name); if ($set !== null) $db = $set; return $db; } @@ -856,6 +857,7 @@ Class Table extends nb { : false ; +#debug($this->db()->name); if ($opt['is_html'] and !$this->p('action') and !$this->p('inc')) { echo $this->html_menu(); } @@ -944,10 +946,8 @@ Class Table extends nb { } # < rows - if (!$count) { - $st->closeCursor(); - return; - } + $st->closeCursor(); + if (!$count) return; $this->count = $opt['count'] = $count; $this->limit = $opt['limit'] = $limit; @@ -1011,8 +1011,6 @@ Class Table extends nb { echo ''.NB_EOL; } - $st->closeCursor(); - return $count; } @@ -1758,11 +1756,6 @@ Class Table extends nb { return $r; } - public function __wakeup() { - global $Db; - $this->db($Db); - } - public function __sleep() { return [ 'name', diff --git a/www/dbq/html/default.css b/www/dbq/html/default.css index 4066e1a1..129f7fdb 100644 --- a/www/dbq/html/default.css +++ b/www/dbq/html/default.css @@ -102,6 +102,7 @@ table.rows tr:last-child td { border-bottom: none; } background-color: #3C3C3B; border-color: #3C3C3B; border-radius: 4px; + padding: 0 0.2em; } a:hover, diff --git a/www/dbq/html/index.php b/www/dbq/html/index.php index c4c4e2e4..aa108f0d 100644 --- a/www/dbq/html/index.php +++ b/www/dbq/html/index.php @@ -2,7 +2,6 @@ # Make it work in php_cli if (empty($_SERVER['DOCUMENT_ROOT'])) $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__); #var_export([$_SERVER['REQUEST_URI']]); -if (empty($_SERVER['SERVER_PROTOCOL'])) $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0'; function run() { $params = parse_uri([ @@ -17,7 +16,9 @@ function run() { # # Page require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/page.php'); - $Page = new Page(); + $Page = new Page([ + 'css' => '/default.css', + ]); $Page->content_type($Page->ext2mime($params['format']) ? $Page->ext2mime($params['format']) : 'text/plain'); #$Page->content_type('text/plain'); #if ($Page->is('text') and !$Page->is('html')) $Page->content_type('text/plain'); @@ -190,6 +191,7 @@ $Page->call([ function not_implemented() { #return http_response_code(501); + if (empty($_SERVER['SERVER_PROTOCOL'])) $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0'; $msg = '501 Not Implemented'; header($_SERVER['SERVER_PROTOCOL'].' '.$msg); echo "$msg\n";