![]() |
Izartu
0.0 Initial release
Web bookmark manager based on tags.
|
00001 <?php 00002 # Izartu 00003 # 00004 # Copyright © 2011-2012 Javier Beaumont <contact@javierbeaumont.org> 00005 # 00006 # This file is part of Izartu. 00007 # 00008 # Izartu is free software: you can redistribute it and/or modify 00009 # it under the terms of the GNU Affero General Public License as 00010 # published by the Free Software Foundation, either version 3 of the 00011 # License, or (at your option) any later version. 00012 # 00013 # Izartu is distributed in the hope that it will be useful, 00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 # GNU Affero General Public License for more details. 00017 # 00018 # You should have received a copy of the GNU Affero General Public License 00019 # along with Izartu. If not, see <http://www.gnu.org/licenses/>. 00020 00031 class Crud extends Database { 00032 00040 final private function process($query) { 00041 if (empty($query)) { 00042 trigger_error('Data not found', E_USER_ERROR); 00043 } else { 00044 $data = $query->fetchAll(PDO::FETCH_ASSOC); 00045 $query->closeCursor(); 00046 return $data; 00047 } 00048 } 00049 00057 final private function save($sql, $param) { 00058 if ($param['id']) { 00059 $query = static::$db->prepare($sql); 00060 $query->bindParam($param['id'][0], $param['id'][1], $param['id'][2], $param['id'][3]); 00061 } else { 00062 $query = static::$db->prepare($id); 00063 } 00064 foreach ($param as $value) { 00065 $query->bindParam($value[0], $value[1], $value[2], $value[3]); 00066 } 00067 $query->execute(); 00068 return $this->process($query); 00069 } 00070 00079 final protected function read($sql, $param = FALSE) { 00080 $query = static::$db->prepare($sql); 00081 if (is_array($param)) { 00082 foreach ($param as $value) { 00083 $query->bindParam($value[0], $value[1], $value[2], $value[3]); 00084 } 00085 } 00086 $query->execute(); 00087 return $this->process($query); 00088 } 00089 00097 final private function delete($sql, $param) { 00098 $query = static::$db->prepare($sql); 00099 foreach ($param as $value) { 00100 $query->bindParam($value[0], $value[1], $value[2], $value[3]); 00101 } 00102 $query->execute(); 00103 return $this->process($query); 00104 } 00105 00106 }
1.7.6.1