From a297f0728f4999fef96e40890fe53b6d46de9884 Mon Sep 17 00:00:00 2001 From: skyverd Date: Sun, 15 Apr 2018 22:18:04 +0800 Subject: [PATCH 1/2] easyCRUD function search miss bindings --- easyCRUD/easyCRUD.class.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/easyCRUD/easyCRUD.class.php b/easyCRUD/easyCRUD.class.php index 6970246..6aaccb4 100644 --- a/easyCRUD/easyCRUD.class.php +++ b/easyCRUD/easyCRUD.class.php @@ -1,6 +1,6 @@ -db = new DB(); + $this->db = new DB(); $this->variables = $data; } @@ -27,7 +27,7 @@ public function __set($name,$value){ } public function __get($name) - { + { if(is_array($this->variables)) { if(array_key_exists($name,$this->variables)) { return $this->variables[$name]; @@ -55,7 +55,7 @@ public function save($id = "0") { if(count($columns) > 1 ) { $sql = "UPDATE " . $this->table . " SET " . $fieldsvals . " WHERE " . $this->pk . "= :" . $this->pk; - if($id === "0" && $this->variables[$this->pk] === "0") { + if($id === "0" && $this->variables[$this->pk] === "0") { unset($this->variables[$this->pk]); $sql = "UPDATE " . $this->table . " SET " . $fieldsvals; } @@ -66,7 +66,7 @@ public function save($id = "0") { return null; } - public function create() { + public function create() { $bindings = $this->variables; if(!empty($bindings)) { @@ -95,8 +95,8 @@ public function find($id = "") { $id = (empty($this->variables[$this->pk])) ? $id : $this->variables[$this->pk]; if(!empty($id)) { - $sql = "SELECT * FROM " . $this->table ." WHERE " . $this->pk . "= :" . $this->pk . " LIMIT 1"; - + $sql = "SELECT * FROM " . $this->table ." WHERE " . $this->pk . "= :" . $this->pk . " LIMIT 1"; + $result = $this->db->row($sql, array($this->pk=>$id)); $this->variables = ($result != false) ? $result : null; } @@ -125,7 +125,7 @@ public function search($fields = array(), $sort = array()) { } $sql .= " WHERE " . implode(" AND ", $fieldsvals); } - + if (!empty($sort)) { $sortvals = array(); foreach ($sort as $key => $value) { @@ -133,13 +133,13 @@ public function search($fields = array(), $sort = array()) { } $sql .= " ORDER BY " . implode(", ", $sortvals); } - return $this->exec($sql); + return $this->exec($sql, $bindings); } public function all(){ return $this->db->query("SELECT * FROM " . $this->table); } - + public function min($field) { if($field) return $this->db->single("SELECT min(" . $field . ")" . " FROM " . $this->table); @@ -163,20 +163,20 @@ public function sum($field) { public function count($field) { if($field) return $this->db->single("SELECT count(" . $field . ")" . " FROM " . $this->table); - } - + } + private function exec($sql, $array = null) { - + if($array !== null) { // Get result with the DB object - $result = $this->db->query($sql, $array); + $result = $this->db->query($sql, $array); } else { // Get result with the DB object - $result = $this->db->query($sql, $this->variables); + $result = $this->db->query($sql, $this->variables); } - + // Empty bindings $this->variables = array(); From c50101276806ca5aa00580f0dfa0d6d0419adef2 Mon Sep 17 00:00:00 2001 From: skyverd Date: Mon, 16 Apr 2018 23:17:03 +0800 Subject: [PATCH 2/2] funciton write init file with a+ , but function edit needs w+ because in this function it will overwrite log --- Log.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Log.class.php b/Log.class.php index 46c294f..f667487 100644 --- a/Log.class.php +++ b/Log.class.php @@ -35,7 +35,7 @@ public function write($message) { if(is_dir($this->path)) { if(!file_exists($log)) { - $fh = fopen($log, 'a+') or die("Fatal Error !"); + $fh = fopen($log, 'w+') or die("Fatal Error !"); $logcontent = "Time : " . $date->format('H:i:s')."\r\n" . $message ."\r\n"; fwrite($fh, $logcontent); fclose($fh);