$DBQ['all']['_import'][] = $id;
}
+if (nb::p('db')!='nb') $DBQ['all']['_import'][] = 'nb';
$a = $b = '';
echo "Start benchmark\n";
-/*
-$a = array('a' => 'A');
-if (isset($a['a'])) echo "OK\n";
-echo realpath('lib/php/default.php')."\n";
-*/
-
/*
print_r(parse_str('first=value&arr[]=foo+bar&arr[]=baz'));
echo $first;
];
protected static $action_help = [
- ['(db.)?help','This help'],
- ['(db.)?ls','List databases from conf'],
- ['(db.)?tables','List tables (name=* type=* count=1 engine=*)'],
+ ['db.help','This help'],
+ ['db.ls','List databases from conf'],
+ ['db.database','List other databases on the same server'],
+ ['db.tables','List tables (name=* type=* count=1 engine=*)'],
- ['(table.)?rows','Dump one table, use format='],
- ['(table.)?fields','List fields'],
- ['table.infos','Table infos (count(*). Type, ...)'],
- ['table.sql','Get the sql source'],
+ ['table.rows','Dump one table, use format='],
+ ['table.fields','List fields'],
+ ['table.status','Table status (count= maxlen= max=)'],
+ ['table.sql','Sql source to create the table'],
- ['(table.)?insert','Insert a record'],
- ['(table.)?update','Update a record'],
- ['(table.)?delete','Delete a record'],
+ ['table.insert','Insert a record'],
+ ['table.update','Update a record'],
+ ['table.delete','Delete a record'],
];
# Web
* Return a table instance
*/
public function table($name='',$params=[]) {
- #if (!array_key_exists($name,$this->tables)) {
if (!$name and !empty($this->default_table)) $name = $this->default_table;
if (!$name) bye('table name is empty');
+
if (empty($this->tables[$name])) {
$this->tables[$name] = new Table($name,['db'=>$this]+$params);
} elseif ($params) {
if (!self::p('table') and ($v = array_keys($Db->tables()))) self::pset('table',$Db->ar_first($v));
if (self::p('table')) $Table = $Db->table(self::p('table'),
- empty($db['tables'][$Db->p('table')]) ? [] : $db['tables'][$Db->p('table')]
+ ( empty($db['tables'][$Db->p('table')]) ? [] : $db['tables'][$Db->p('table')] )
);
}
return 'csv';
}
}
+
public function page($opt=[]) {
+ require_once(realpath(dirname(__FILE__).'/page.php'));
return new Page(array_merge([
'title' => ($this->title ? $this->title : this::prettyText($this->name)),
'css' => [
<?php
require_once(realpath(dirname(__FILE__).'/../config.php'));
-require_once(realpath(dirname(__FILE__).'/../db.php'));
+# NB 04.12.16 require_once(realpath(dirname(__FILE__).'/../db.php'));
require_once(realpath(dirname(__FILE__).'/config.php'));
$HEAD = &$opt['var']['head'];
$ROWS = &$opt['var']['rows'];
$ROW = &$opt['var']['rows'][0];
+ foreach ($ROWS as $key=>$row) {
+ $i=0;
+ foreach ($row as $k=>$v) {
+ $ROWS[$key][$i] = $v;
+ $i++;
+ }
+ }
#$opt['var']['rows']=[];
$_REQUEST_BAK = $_REQUEST;
+++ /dev/null
-<?php
-if (!defined('DEBUG')) define('DEBUG',(int)@$_REQUEST['debug']);
-ini_set('include_path', realpath(dirname(__FILE__)).':'.ini_get('include_path'));
-
-require_once((dirname(__FILE__).'/functions.php'));
-require_once((dirname(__FILE__).'/page.php'));
-?>
--- /dev/null
+<?php
+if (!defined('DEBUG')) define('DEBUG',(int)@$_REQUEST['debug']);
+ini_set('include_path', realpath(dirname(__FILE__)).':'.ini_get('include_path'));
+
+require_once((dirname(__FILE__).'/functions.php'));
+require_once((dirname(__FILE__).'/page.php'));
+?>
s/^define(\([^,]\+\)/if (!defined(\1)) define(\1/
*/
-// NB 28.06.15 require_once((dirname(__FILE__).'/default.php'));
function file_write($file,$data,$mode='w') {
return nb::file_write($file,$data,$mode);
}
function err($msg='__err__',$preff='err',$backtrace_deep=0) {
-# NB 05.04.16 $msg = is_scalar($msg) ? $msg : print_r($msg,true);
$msg = is_scalar($msg) ? $msg : print_r($msg,true);
$preff_msg = $preff ? strtoupper($preff).': ' : '';
if ($msg !== '__err__' and $backtrace_deep !== false) {
'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'xml' => 'application/xml',
+ 'txt' => 'text/plain',
'csv' => 'text/csv',
'html' => 'text/html',
- 'txt' => 'text/plain',
'yaml' => 'text/yaml',
+ 'php' => 'text/x-php',
);
#public static function zaza() { return (is_object($this) ? 'TRUE' : 'FALSE'); }
public $h1 = '';
public $sep = ' / ';
- /*
- New
- */
+ public function call($calls) {
+ foreach ((array)($calls) as $call) {
+
+ if (is_scalar($call)) {
+ $this->$call();
+
+ } elseif ( is_array($call) ) {
+ $k = $call[0];
+ $this->$k($call[1]);
+
+ } elseif (is_callable($call)) {
+ $call($this);
+
+ }
+
+ }
+
+ }
+
public function __construct($opt = []) {
// Content-type
if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title;
// Call / Print
-
- // Nav
- foreach ((array)($this->call) as $call) {
-
- if (is_scalar($call)) {
- $this->$call();
-
- } elseif ( is_array($call) ) {
- $k = $call[0];
- $this->$k($call[1]);
-
- } elseif (is_callable($call)) {
- $call($this);
-
- } else {
-
- }
-
- }
+ if (!empty($this->call)) $this->call($this->call);
}
public function headers() {
#header('Content-type: ' . self::$content_type);
+ self::$content_type = 'text/plain';
header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : ""));
if (isset($this->expires)) self::headers_cache($this->expires);
return join("\n",$m[0]);
}
- public function infos() {
+ public function status() {
$out = array(
'path' => self::path()
);
if (!$format and $content_type) {
self::p('format',self::mime2ext($content_type));
+
} elseif (!$format and ($client_type = self::client_content_type())) {
self::p('format',self::mime2ext($client_type));
+
}
if (!$content_type and $format) $content_type = self::ext2mime($format);
'ip',
'addr',
'address',
+ 0,
] as $k) {
if (!isset($r[$k])) continue;
$line[] = $r[$k];
'host',
'name',
'id',
+ 1,
] as $k) {
if (!isset($r[$k])) continue;
$line[] = $r[$k];
<?php
# NB 02.12.16: Nginx LB
-if (!isset($ROWS)) continue;
+if (!isset($ROWS)) return;
+
$lb = [];
+
foreach ($ROWS as $r) {
$lb[$r[0]][] = $r[1];
$name = $r[0];
$server = $r[1];
+
continue;
foreach ([
'hostname',
break;
}
}
+
foreach ($lb as $name => $servers) {
echo "upstream $name {\n";
foreach ($servers as $server) {
--- /dev/null
+DROP TABLE IF EXISTS http_status;
+CREATE TABLE http_status(id int primary key,name varchar(100),description varchar(1000));
+DELETE FROM http_status;
+.sep "\t"
+.import /Users/nico/tmp/http_status.txt http_status
+-- SELECT * FROM http_status limit 5;
$params = [
#'db',
- 'action',
'table',
+ 'action',
'format',
];
-# NB 03.12.16 list(
-# NB 03.12.16 $action,
-# NB 03.12.16 $db,
-# NB 03.12.16 $table,
-# NB 03.12.16 $format,
-# NB 03.12.16 ) =
-#if (strpos($_SERVER['REQUEST_URI'],'?')!==false) return header('HTTP/1.1 501 Not Implemented');
-if (strpos($_SERVER['REQUEST_URI'],'?')!==false) return http_response_code(501);
-$values = explode('/',$_SERVER['REQUEST_URI']);
-while (count($values)>0 and $values[0]==='') {
- array_shift($values);
+if (false and strpos($_SERVER['REQUEST_URI'],'?')!==false) {
+ #return http_response_code(501);
+ $msg = '501 Not Implemented';
+ header($_SERVER['SERVER_PROTOCOL'].' '.$msg);
+ echo "$msg\n";
+ return;
}
-#for ($i=count($values);$i>0 and $values[
+$_SERVER['REQUEST_URI'] = preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']);
+$values = explode('/',trim($_SERVER['REQUEST_URI'],'/'));
require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/page.php');
-#debug($_SERVER['REQUEST_URI']);
+#bye($_REQUEST);
foreach ($values as $k=>$v) {
+ #if ($v!=='') debug($params[$k].'='.$v);
if ($v!=='') Page::pdef($params[$k],$v);
}
Page::pdef('format','human');
-Page::pdef('action','ls');
+#Page::pdef('action','db.ls');
require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/db/init.php');
-$Db->page([
- 'call' => [
+header('Content-type: text/plain');
+$Page = $Db->page();
+$Page->headers_no_cache();
+$Page->call([
+# NB 04.12.16 $Db->page([
+# NB 04.12.16 'call' => [
'begin',
#['out', "Hello World !!!\n"],
function($page) use($Db){
- if (!$page->action()) return $Db->action($Db->p('action'),$Db->table());
+ #debug($Db->p());
+ #global $values; debug($values);
+ },
+ function($page) use($Db){
+ if (!$page->action()) return $Db->action($Db->p('action'),$Db->table($Db->p('table')));
},
function($page) use($Db){
- #global $values; debug($values);
if (!$page->is('html')) return;
if (!empty($Db)) echo $page->tag('p class="db-infos"',join(' | ',[
$Db->type,
},
'end',
- ],
+# NB 04.12.16 ],
]);
#require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/db/page.php');
# /DB/ACTION/[TABLE]/[FORMAT]