diff options
-rw-r--r-- | App.php | 2 | ||||
-rw-r--r-- | Controller.php | 29 | ||||
-rw-r--r-- | Db.php | 4 |
3 files changed, 14 insertions, 21 deletions
@@ -139,9 +139,11 @@ class App return false; } + $msg = trim($msg); $fh = fopen($file, "a+"); fwrite($fh, trim($msg) . "\n"); fclose($fh); + } /** diff --git a/Controller.php b/Controller.php index 84947b0..22dccc6 100644 --- a/Controller.php +++ b/Controller.php @@ -221,14 +221,9 @@ class Controller * Insert this thing in the DB and return inserted * thing */ - public function insert($data = null) + public function insert($data) { - if (!$data) { - $data = $_POST; - } - if (empty($data)) { - App::log("Attempted to insert empty data"); return App::error("Nothing to insert"); } @@ -252,17 +247,17 @@ class Controller /** * Delete this thing */ - public function delete() + protected function delete($where) { - if (empty($_POST)) { - exit(App::error("Delete without arguments")); + if (empty($where)) { + return App::error("Delete without arguments"); } - list($key, $value) = each($_POST); - - $sql = "DELETE FROM `{$this->table}` WHERE `{$key}` = ?"; + list($key, $value) = each($where); + $data = array(":{$key}" => $value); + $sql = "DELETE FROM `{$this->table}` WHERE `{$key}` = :{$key}"; - return DB::query($sql, $value); + return Db::query($sql, $data); } @@ -271,13 +266,9 @@ class Controller * We keep this in the Controller since it might know * more about the topmost class */ - public function update($data = null, $where = null) + protected function update($data, $where = null) { - if (!$data) { - $data = $_POST; - } - - if (empty($data)) { + if (!is_array($data)) { return App::error("Update with empty parameters"); } @@ -54,7 +54,7 @@ class Db * Execute an SQL query * @return mixed */ - public function query($sql, $data = null) + public static function query($sql, $data = null) { if (!$data) { $data = array(); @@ -104,7 +104,7 @@ class Db } - public function fetch($sql, $data = null) + public static function fetch($sql, $data = null) { $stmt = self::query($sql, $data); return $stmt->fetchAll(PDO::FETCH_ASSOC); |