#模型 model
>[success]模型主要功能是操作数据库
###数据库操作有一下几种类型
1. Execute 执行
1. GetRow 取单条数据
1. GetAll 取多条数据
1. createPage 分页
##在model下调用sql类
>[info] 删除数据
>[info]**$this->Execute(SqlToolsClass::DeleteData(表名,条件));**
>[info]取单条数据
>[info]**$this->GetRow(SqlToolsClass::SelectItem(表名,条件,字段,join,order,group,limit,having));**
>[info]取多条数据
>[info]**$this->GetRow(SqlToolsClass::SelectItem(表名,条件,字段,join,order,group,limit,having));**
>[info]分页数据
>[info]**$this->createPage(SqlToolsClass::SelectItem(表名,条件,字段,join,order,group,limit,having));**
>[info]获取表名
>[info]**SqlToolsClass::getTableName(表名);**
>[info]新增一条数据
>[info]**$this->Execute(SqlToolsClass::InsertData(表名,一维数组));**
>[info]新增多条数据
>[info]**$this->Execute(SqlToolsClass::InsertDatas(表名,二维数组));**
>[info]更新数据
>[info]**$this->Execute(SqlToolsClass::EditData(表名,数组,条件));**
##demo
~~~
<?php
class coreModelAdmin extends coreFrameworkModel
{
function __construct()
{
parent::__construct();
}
function delManagerMenu($id){
$sql=SqlToolsClass::DeleteData("manager_menu", "id=$id");
return $this->Execute($sql);
}
function delMenu($id){
$sql=SqlToolsClass::DeleteData("menu", "id=$id");
return $this->Execute($sql);
}
//获取管理员用户
function getAdminList($get){
$join="left join ".SqlToolsClass::getTableName("admin_group")." as g on g.id=a.gid ";
$sql=SqlToolsClass::SelectItem("admin as a",null,"a.*,g.title as group_title",$join,null,"a.id");
return $this->createPage($sql);
}
function getAdmin($id){
$sql=SqlToolsClass::SelectItem("admin","id=$id");
return $this->GetRow($sql);
}
function delAdmin($id){
$sql=SqlToolsClass::DeleteData("admin", "id=$id");
return $this->Execute($sql);
}
function updataUserLogin($data,$id){
$sql=SqlToolsClass::EditData("admin", $data, "id=$id");
$this->Execute($sql);
}
function getGroup($id,$status){
if ($status){
$sql=SqlToolsClass::SelectItem("admin_group",$where);
return $this->GetAll($sql);
}else{
if ($id) $where="id=".$id;
$sql=SqlToolsClass::SelectItem("admin_group",$where);
return $this->GetRow($sql);
}
}
function saveAuth($id,$data){
$sql=SqlToolsClass::DeleteData("admin_group_auth", "gid=$id");
$this->Execute($sql);
$sql=SqlToolsClass::InsertDatas("admin_group_auth", $data);
return $this->Execute($sql);
}
function getAuth($id){
$sql=SqlToolsClass::SelectItem("admin_group_auth","gid=$id");
return $this->getAll($sql);
}
}
?>
~~~