首页 > 其他 > 详细

时间:2014年3月30日15:09:01自动加载及防止非法访问

时间:2014-03-31 03:10:52      阅读:505      评论:0      收藏:0      [点我收藏+]


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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!