class Model{ protected $table = null;//model所控制的表 protected $db= null;//引入的mysql对象 protected $pk = ‘‘; public function __Construct(){ $this->db = mysql::getIns(); } public function table($table){ //表名可以任意赋值 $this->table = $table; } public function add($data){ return $this->db->autoExcute($this->table,$data); } public function delete($id){ $sql = "delete from ".$this->table." where ".$this->pk." = ".$id; if ($this->db->query($sql)) { return $this->db->affected_rows(); }else{ return false; } } // public function update($data,$id){ $rs = $this->autoExcute($this->table,$data,‘update‘,‘where ‘.$this->pk.‘ = ‘.$id); if ($rs) { return $this->db->affected_rows(); }else{ return false; } } public function select(){ $sql = ‘select * from ‘.$this->table; return $this->db->getAll($sql); } public function find($id){ $sql = "select * from ".$this->table." where ".$this->pk." = ".$id; return $this->db->getRow($sql); } } ?> |
自动加载
在init.php中修改
//自动加载 function __autoload($class){ /* stripos($haystack, $needle)从$haystack查找$needle */ if ( strtolower(substr($class, -5)) == ‘model‘) { require(ROOT.‘/Model/‘.$class.‘.class.php‘); } else { require(ROOT.‘include/‘.$class.‘.class.php‘); } } |
防止非法访问:
在不能访问页面,init.php
defined("ACC") || exit(‘ ACC Denied‘); |
在可以访问页面:
define("ACC", true); require("./include/init.php"); |
本文出自 “杜国栋个人PHP学习博文” 博客,请务必保留此出处http://duguodong.blog.51cto.com/7667978/1387197
时间:2014年3月30日15:09:01自动加载及防止非法访问,布布扣,bubuko.com
时间:2014年3月30日15:09:01自动加载及防止非法访问
原文:http://duguodong.blog.51cto.com/7667978/1387197