<?php
function C($name,$method){
//引入控制器文件 实例化控制器 调用其中方法
require_once('/libs/Controller/'.$name.'Controller.class.php');
// eval('$obj=new '.$name.'Controller();$obj->'.$method.'();');
$a=$name.'Controller';
$obj=new $a();
$obj->$method();
}
function M($name){
require_once('/libs/Model/'.$name.'Model.class.php');
eval('$obj=new '.$name.'Model();');
return $obj;
}
function V($name){
require_once('/libs/View/'.$name.'View.class.php');
eval('$obj=new '.$name.'View();');
return $obj;
}
function ORG($path,$name,$params=array()){
require_once('libs/ORG/'.$path.$name.'.class.php');
$obj=new $name();
if(!empty($params)){
foreach ($params as $key => $value) {
$obj->$key=$value;
//eval('$boj->'.$key.'=\''.$value.'\');
}
}
return $obj;
}
function daddslashes($str){
return (!get_magic_quotes_gpc())?addslashes($str):$str;
}
操作数据库的:
<?php
class mysql{
//错误输出
function err($error){
die('error'.$error);
}
//连接数据库
function connect($config){
extract($config);
//dbhost,dbuser,dbpsw ,dbcharset
if(!$con=mysql_connect($dbhost,$dbusder,$dbpsw)){
$this->error(mysql_error());
}
if(!mysql_select_db($dbname,$con)){
$this->error(mysql_error());
}
mysql_query('set names'.$dbcharset);
// mysql_query('set names utf8');
}
//执行sql语句
function query($sql){
if(!($query==mysql_query($sql))){
$this->error("$sql".mysql_error());
}else{
return $query;
}
}
//列表
function findAll($query){
while($rs=mysql_fetch_array($query,MYSQL_ASSOC)){
$list[]=$rs;
}
return isset($list)?$list:'';
}
//单条
function findOne($query){
$rs=mysql_fetch_array($query,MYSQL_ASSOC);
return $rs;
}
// 指定从0开始,字段。指定行指定字段数据
function findResult($query,$row=0,$field=0){
$rs=mysql_result($query,$row,$field);
return $rs;
}
function insert($table,$arr){
// 传递字段和值一一对应的数组
//$sql="insert into test(a,b,c) values('1','3','3')";
foreach ($arr as $key => $value) {
$value=mysql_real_escape_string($value);
$keyArr[]="`".$key."`";
$valueArr[]="'".$value."'";
}
$keys=implode(',', $keyArr);
$values=implode(','.$valueArr);
$sql="insert into ".$table.".(".$keys.") values(".$values.")";
$this->query($sql);
return mysql_insert_id();
}
function update($table,$where,$arr){
// update demo set 字段 =值 where
foreach ($arr as $key => $value) {
$value=mysql_real_escape_string($value);
// `name`='tom'
$keyAndvalueArr[]="`".$key."`="."'".$value."'";
}
$keyAndvalues=implode(',', $keyAndvalueArr);
$sql="update ".$table." set ".$keyAndvalues." where ".$where;
$this->query($sql);
}
function del($table,$where){
$sql="delete from ".$table." where ".$where;
$this->query($sql);
}
}