From cb6a51a32f494ae5f64e5db4576ce61e116b2533 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 3 Nov 2016 22:25:05 +0100 Subject: [PATCH] Forgot --- lib/php/db.php | 30 +++++++++++++++++++++++++++--- lib/php/db/table.php | 1 + lib/php/nb.php | 15 ++++++++++----- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 753ab5ba..68dcb15c 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -14,6 +14,14 @@ $DB_TYPES = []; # See db/types/*.php #$arr = ['rent'=>'Rent','nb'=>'Nb']; #if (!empty($argv) and $argv[1] == 'zaza') bye($arr); +if (defined('PRODUCTION')) { + define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_SILENT); +} else { + define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_EXCEPTION); + #define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_WARNING); +} + +#const DB::ERRMODE=''; class Db extends nb { # PDO Connection @@ -26,7 +34,9 @@ class Db extends nb { public $conn; public $pdo; - public $options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING]; # See: http://php.net/manual/en/pdo.error-handling.php + public $options = [ # See: http://php.net/manual/en/pdo.error-handling.php + PDO::ATTR_ERRMODE => DB_DEFAUL_ERRMODE, + ]; public $host = null; public $port = null; public $user = null; @@ -440,6 +450,19 @@ class Db extends nb { return $this->conf_type($key,$die); } + public function table_exist($table) { + # NB 02.11.16: TODO NEVEW USED + $table = is_object($table) ? $table->name : $table; + + if ($this->_tables === true) { + if (array_key_exists($table)) return 1; + } else { + } + + return null; + + } + public function tables() { if (!isset($this->_tables)) { @@ -450,9 +473,10 @@ class Db extends nb { if ($sql and !empty($this->conn)) { foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) { - #debug($row); $name = current($row); - $t = $this->table($name,$row+['status'=>$row]); # add to this->tables too ! + + # add to this->tables !!! + $t = $this->table($name,$row+['status'=>$row]); } } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 5beed0cc..ea6ea092 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -277,6 +277,7 @@ Class Table extends nb { $conf = $this->unvar($this->db()->conf_type('table.fields',true)); if (is_scalar($conf)) $conf = array('sql'=>$conf); $rows = $this->db()->conn->query($conf['sql']); + $rows->setFetchMode(PDO::FETCH_ASSOC); // Get other indexes diff --git a/lib/php/nb.php b/lib/php/nb.php index 2e70d6c5..046251a9 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -1,11 +1,8 @@ test()); #if (!defined('NB_PARAMS')) define('NB_PARAMS',$_REQUEST); @@ -318,6 +315,14 @@ class NB { * Function: yaml_encode */ public static function yaml_encode($row) { + static $Spyc; + if (empty($Spyc) and !function_exists('yaml_emit')) { + require_once(realpath(dirname(__FILE__).'/Spyc.php')); + function yaml_emit($data) { return Spyc::YAMLDump($data, false, false, true); } + function yaml_parse_file($file) { return Spyc::YAMLLoad($file); } + $Spyc = true; + } + $yaml = yaml_emit($row); $yaml = preg_replace('/^---\s*/','',$yaml); $yaml = preg_replace('/\n\.\.\.$/','',$yaml); -- 2.47.3