From: Nicolas Boisselier Date: Mon, 6 Jul 2015 00:18:07 +0000 (+0100) Subject: Fix conn bug X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=aaf0d228b8b46fb65c5bc0cc8e210b424789ffcb;p=nb.git Fix conn bug --- diff --git a/lib/php/db.php b/lib/php/db.php index 97229234..a6b2b3a5 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -13,6 +13,7 @@ class db { public $tables = array(); public $conn; + public $title; public $type; public $help_criterias = array( ' * or % for wildcar', @@ -21,12 +22,19 @@ class db { ' combine criterias with OR/AND', ); - function __construct($pdo) { - $this->conn = new PDO($pdo); - $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$pdo)); + function __construct($db) { + + $db = is_scalar($db) ? array('conn' => $db) : $db; + foreach ($db as $k=>$v) $this->$k = $v; + $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$db['conn'])); + + #bye($db['conn']); + $this->conn = new PDO($db['conn']); if ($this->type == 'sqlite') { + if (empty($this->title)) $this->title = preg_replace('/^.*?:.*(.*?)(\.\w+)?$/','\1',$db['conn']); + $this->conn->sqliteCreateFunction('regexp', function ($pattern, $data, $delimiter = '~', $modifiers = 'isuS') { if (isset($pattern, $data) === true) { @@ -148,7 +156,7 @@ EOF; function print_header($type) { if ($this->p('format')=='csv') { - header('Content-type: text/plain'); + header('Content-type: text/csv'); } elseif ($this->p('format')=='yaml') { header('Content-type: text/yaml'); @@ -965,13 +973,14 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } function rows_rec_div($row) { + echo '