From 1b844104d991544bef44fc954cd613e861ef480c Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 14 Jul 2015 16:16:13 +0100 Subject: [PATCH] update, add, delete --- lib/php/db.php | 8 ++++---- lib/php/db/table.php | 18 +++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 07692b93..f53e35d8 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -11,9 +11,9 @@ require_once(dirname(__FILE__).'/db/table.php'); require_once(dirname(__FILE__).'/db/field.php'); if (!defined('DB_ERR_PRINT')) define('DB_ERR_PRINT',false); if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS','' - .'' - .'X' .'' + .'X' + .'' ); if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD',''); if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT',''); @@ -43,8 +43,8 @@ class db { $this->conn = new PDO($db['conn']); if (DB_ERR_PRINT) $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { - err($e->getMessage(), "connecthrsedb"); - return $e; + err($e->getMessage(), "Db.new()"); + return false; } #if (empty($this->name)) $this->name = preg_replace('/^(?:(?:sqlite:.*(.*?)(\.\w+)?)|(?:.*?dbname=([^;]+).*?))$/','\1',$db['conn']); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 5e721ba5..c30ac292 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -81,10 +81,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach ($rows as $row) { $this->fields[$row['name']] = array( - 'extra' => null, - 'type' => null, - 'default' => null, - 'key' => null, + 'extra' => null, + 'type' => null, + 'default' => null, + 'key' => null, + 'autoincrement' => false, ); $this->fields[$row['name']]['type'] = $row['type']; @@ -771,9 +772,12 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. if (!$where) return 0; $sql = 'DELETE FROM ' . $this->sql_name() . $where; debug($sql); - $execute = $this->db->query($sql); - if (!$execute) return err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .PHP_EOL); - return $execute; + try { + $this->db->query($sql); + } catch (PDOException $e) { + return err($e->getMessage(), "Table.delete()"); + } + return true; } } -- 2.47.3