$type = self::p('type','');
foreach ($this->tables() as $t) {
-# NB 27.06.16 if (!empty($name) and strpos($t->name,$name) === false) continue;
- if (!empty($name) and !preg_match('/'.$name.'/',$t->name)) continue;
- if (!empty($type) and strpos($t->type,$type) === false) continue;
+ if (!empty($name) and !$this->str_match($t->name,$name)) continue;
+ if (!empty($type) and !$this->str_match($t->type,$type)) continue;
$rows[] = $t->infos();
}
} elseif ($action == 'db.dbs' or $action == 'dbs') {
if (self::p('hash') or self::p('all')) {
+
$fields = ['id','name','host','type'];
$dbs = [];
$name = self::p('name','');
$type = self::p('type','');
+
foreach ($this->conf as $id => $attr) {
$d = new Db();
foreach ($attr as $k=>$v) $d->$k = $v;
$d->connect_init();
$db = []; $d->id = $id;
+
foreach ($fields as $k) {
if (!isset($d->$k)) continue; $db[$k] = $d->$k;
}
-# NB 27.06.16 if (!empty($name) and strpos($db['name'],$name) === false) continue;
- if (!empty($name) and !preg_match('/'.$name.'/',$db['name'])) continue;
- if (!empty($type) and strpos($db['type'],$type) === false) continue;
+
+ if (!empty($name) and !$this->str_match($db['name'],$name)) continue;
+ if (!empty($type) and !$this->str_match($db['type'],$type)) continue;
$dbs[] = $db;
}
+
$return = $this->out($dbs,$fields);
+
}
else $return = $this->out($this->dbs,"id");
foreach ($tables as $t) {
if (!empty($tables) and empty($tables[$t->name])) continue;
- if (!empty($type) and strpos($t->type,$type) === false) continue;
-# NB 27.06.16 if (!empty($name) and strpos($t->name,$name) === false) continue;
- if (!empty($name) and !preg_match('/'.$name.'/',$t->name)) continue;
+ if (!empty($name) and !$this->str_match($t->name,$name)) continue;
+ if (!empty($type) and !$this->str_match($t->type,$type)) continue;
if ($insert) {
echo "\n-- ".strtoupper($t->type).": ".$t->name."\n";
if (!defined('NB_EOL')) define('NB_EOL',defined('NB_PROD') ? '' : "\n");
require_once(realpath(dirname(__FILE__).'/functions.php'));
#$nb = new NB(); debug($nb->test());
-/*
-if (empty($_SERVER['DOCUMENT_ROOT'])) var_export([
- '~0 : 0' => nb::str_match('~0','0'),
- 'null : 0' => nb::str_match('null','0'),
- 'null : ""' => nb::str_match('null',''),
- '!null : ""' => nb::str_match('!null',''),
- '!~zaz : "zaza"' => nb::str_match('!~zaz','zaza'),
- '~zaz : "zaza"' => nb::str_match('~zaz','zaza'),
- 'za* : "zaza"' => nb::str_match('za*','zaza'),
-]);
-*/
if (class_exists('NB')) return;
class NB {
}
}
- public static function str_match($pattern,$string) {
+ public static function str_match($string,$pattern) {
$match = false;
// No empty values