#
#-e $ROOT_DIR.'/lib/php/db/index.php' && die 'OK';
my $url = ($ENV{$UC_NAME.'_URL'} ? $ENV{$UC_NAME.'_URL'} :
- ( -e $ROOT_DIR.'/lib/php/db/index.php' ? $ROOT_DIR.'/lib/php/db/index.php' : '/opt/rent/www/index.php' )
+ ( -e $ROOT_DIR.'/lib/php/db/dbq.php' ? $ROOT_DIR.'/lib/php/db/dbq.php' : '' )
);
if (!$Opt{ssh} and @ARGV and ($ARGV[0] =~ m|^\w+://| or -e $ARGV[0] )) {
$url = shift @ARGV;
public function action($action,$table=null) {
#debug(($this->tables));
- $available = self::$action_help;
$actions = explode(',',$action);
- $this->pdef('format',($this->php_cli() ? 'csv' : ''));
+# NB 02.12.16 $this->pdef('format',($this->php_cli() ? 'csv' : ''));
$rows = [];
$return = false;
foreach($actions as $action) {
if ($action == 'db.help') {
- $this->out($available,['action','description']);
+ $this->out(self::$action_help,['action','description']);
$return = true;
} elseif ($action == 'db.exec') {
global $Db, $Table;
if (isset($Table)) self::bye("Table.init(): GLOBALS['Table'] already exists !");
if (isset($Db)) self::bye("Db.init(): GLOBALS['Db'] already exists !");
+
$Db = new self();
$Db->pinit();
-
if (empty($Db)) return false;
+
$db = $Db->conf_search_db($conf);
if ($Db->p('localFile')) {
foreach ($Db->localFile($db['name']) as $k=>$v) {
# Connection
$Db->__construct($db);
-# NB 21.09.16 if (empty($Db->_no_connect)) {
$Db->connect();
-# NB 21.09.16 }
/*
Table
!self::p('table') and
!preg_match('/^(table\.\w+|rows|insert|edit|delete|update)$/',self::p('action'))
) {
+
} else {
# Search default_table
return $row;
}
+ public static function content_type2format($content_type) {
+ if (empty($content_type)) $content_type = self::client_content_type();
+ switch (self::mime2ext($content_type)) {
+ case "html":
+ return 'table';
+ case "txt":
+ return 'human';
+ default:
+ return 'csv';
+ }
+ }
#public function default_table() { return $this->default_table; }
} # < Class
--- /dev/null
+<?php
+#!/usr/bin/env php
+/**
+* @copyright (C) 2016 Nicolas Boisselier
+* @author Nicolas Boisselier nicolas.boisselier@gmail.com
+*
+* lib/php/db/dbq.php
+*/
+require_once(realpath(dirname(__FILE__).'/init.php'));
+$Db->pdef('format',$Db->content_type2format());
+return $Db->action($Db->p('action'),$Table);
+?>
*/
#require_once(realpath(dirname(__FILE__).'/page.php')); return;
require_once(realpath(dirname(__FILE__).'/init.php'));
-
if(defined('DB_NO_ACTION') and DB_NO_ACTION) return true;
-# Happend when include from a function
+# Needed when include from a function
if (!isset($Db)) global $Db, $Table;
-switch ($Db->mime2ext($Db->client_content_type())) {
- case "html":
- $Db->pdef('format','table');
- break;
- case "txt":
- $Db->pdef('format','human');
- break;
- default:
- #bye($type);
- $Db->pdef('format','json');
-}
+$Db->pdef('format',$Db->content_type2format());
return $Db->action($Db->p('action'),$Table);
?>
require_once(dirname(__FILE__).'/init.php');
require_once(dirname(__FILE__).'/../page.php');
+
$Page = new Page([
'title' => ($Db->title ? $Db->title : Db::prettyText($Db->name)),
'css' => [
function($page){
global $Db, $Table;
- #$type = $page->mime2ext($page->content_type());
- switch ($page->mime2ext($page->content_type())) {
- case "html":
- $page->pdef('format','table');
- break;
- case "txt":
- $page->pdef('format','human');
- break;
- default:
- #bye($type);
- $page->pdef('format','csv');
- }
+ $Db->pdef('format',$Db->content_type2format($page->content_type()));
if (!$page->action()) return $Db->action($Db->p('action'),$Table);
},
}
public function action($action=null) {
- if ($action === null) $action = $this->p('action');
+ #if (empty($action)) return;
+ #if ($action === null) $action = $this->p('action');
+ #debug($action);
if ($action == 'table.fields') {
$rows = array_values($this->object2array($this->fields()));
} elseif ($action == 'table.rows') {
$this->db()->print_header($this->p('format'));
- $this->rows(); return true;
+ $this->rows();
+ return true;
} elseif ($action == 'table.info') {
return $this->out($this->info());
}
public function template($id=null) {
- if (empty($id) and !( $id=self::p('table.template.id') ) ) self::bye('Wrong parameter!');
+ if (empty($id)
+ and !( $id=self::p('table.template.id') )
+ and !( $id=self::p('idtemplate') )
+ ) self::bye('Wrong parameter!');
$id = preg_replace('/[^\w\._-]/','',$id);