]> git.nbdom.net Git - nb.git/commitdiff
Forgot
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 3 Nov 2016 21:25:05 +0000 (22:25 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 3 Nov 2016 21:25:05 +0000 (22:25 +0100)
lib/php/db.php
lib/php/db/table.php
lib/php/nb.php

index 753ab5ba863cf70563f2b735043b383a8044e634..68dcb15c7571961d4222aab6a186eb9a3ce51548 100644 (file)
@@ -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]);
         }
       }
 
index 5beed0cc40a820e40df26b691b9389223c0542fd..ea6ea09297f5ae8ed62e82be45e566ea59af9d61 100644 (file)
@@ -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
index 2e70d6c57bc111ebd8b49df26eaa2e9f11a0930d..046251a9c6f40100d65ad64cd9fead647268e1b4 100644 (file)
@@ -1,11 +1,8 @@
 <?php
 if (!defined('NB_ROOT')) define('NB_ROOT',realpath(dirname(__FILE__).'/../..'));
+if (defined('PRODUCTION') and !defined('NB_PROD')) define('NB_PROD',PRODUCTION);
 if (!defined('NB_EOL')) define('NB_EOL',defined('NB_PROD') ? '' : "\n");
-if (!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); }
-}
+
 require_once(realpath(dirname(__FILE__).'/functions.php'));
 #$nb = new NB(); debug($nb->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);