#$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
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;
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)) {
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]);
}
}
$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
<?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);
* 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);