角色权限管理系统(工具类部分)
来源:互联网 发布:新卷皮 淘宝客 源码 编辑:程序博客网 时间:2024/04/25 09:14
为了更好的开发,这次项目我写了几个比较有用的工具类主要就围绕数据库操作、分页、session来弄的一起来看看吧
1.数据库连接工具类
<?php class DBUtil{ private $host="localhost"; private $username="root"; private $password="123456"; private $dbname="humanresource"; private $conn; public function DBUtil(){ $this->conn=new mysqli($this->host, $this->username, $this->password,$this->dbname) or die($this->conn->connect_error); } public function getConnection(){ return $this->conn; } public function close(){ if($this->conn){ $this->conn->close(); } } }?>
这个类主要用于取得或关闭数据库连接
2.数据库操作类
<?phpclass BaseDBOperate { public function query($sql,$conn){ //设置查询编码,我本地的数据库编码为UTF-8 $conn->query("set names utf8"); $result= $conn->query($sql) or die($conn->error); $arr = array (); $i=0; while ($row = $result->fetch_assoc()) { $arr[$i++] = $row; } $result->free(); //$conn->close(); return $arr; } public function otherOperate($sql,$conn){ $conn->query("set names utf8"); if($conn->query($sql)){ if($conn->affected_rows>0){ return "1"; }else{ return "0"; } } } //分页查询 public function findAll($pageSql, $totalPageSql, $fenyePage,$conn) { $conn->query("set names utf8"); $result = $conn->query($pageSql); $arr = array (); $i=0; while ($row = $result->fetch_assoc()) { $arr[$i++] = $row; } $result->free(); //获取分页所需要的显示数据 $fenyePage->fenyeArray = $arr; //获取总的数据行数 $res2 = $conn->query($totalPageSql) or die($this->conn->error); if ($rows = $res2->fetch_row()) { //获取总的页数 $fenyePage->sumPage = ceil($rows[0] / $fenyePage->everyPageRows); } //释放资源 $res2->free(); } //循环删除数据 function loopDelete($sqls,$conn){ $conn->query("set names utf8"); $temp=0; $flag="0"; for($i=0;$i<count($sqls);$i++){ if($conn->query($sqls[$i])){ if($conn->affected_rows>0){ $temp++; } } } if($temp>0){ $flag="1"; }else{ $flag="0"; } return $flag; } }?>
3.比较简单的分页组件,虽然有点小瑕疵但还是很好用
<?phpclass fenyePage {public $everyPageRows; //每页显示的行数public $sumPage; //总页数public $nowPage; //当前所在页数public $fenyeArray; //分页显示的数据public $navigate; //分页导航条public $pageWhole; //翻页页数public $url; //翻页页数function showNavigate() {echo "<ul class='fenye_ul'>";echo "<a href='$this->url&nowPage=1'><li>首页</li></a>";if ($this->nowPage > 1) {echo "<a href='$this->url&nowPage=" . ($this->nowPage - 1) . "'><li class='btn'>上页</li></a>";}//翻页$startPage = floor(($this->nowPage-1) / $this->pageWhole) * $this->pageWhole + 1;$index = $startPage;//如果当前页是在1到10之间,就没有必要显示向前翻页的链接if ($this->nowPage > $this->pageWhole) {echo "<a href='$this->url&nowPage=" . ($startPage -1) . "'><li><b><<</b></li></a>";}for (; $startPage < $index + $this->pageWhole; $startPage++) {if ($startPage == $this->nowPage) {echo "<a href='$this->url&nowPage=$startPage'><li style='background:#6699cc;'>$startPage</li></a>";} else {echo "<a href='$this->url&nowPage=$startPage'><li>$startPage</li></a>";}}//如果startPage的值小于总的页数,就显示向后翻译if ($startPage < $this->sumPage) {echo "<a href='$this->url&nowPage=$startPage'><li><b>>></b></li></a>";}if ($this->nowPage < $this->sumPage) {echo "<a href='$this->url&nowPage=" . ($this->nowPage + 1) . "'><li>下页</li></a>";}echo "<a href='$this->url&nowPage={$this->sumPage}'><li>末页</li></a>";echo "<li>共{$this->sumPage}页</li>";echo "</ul>";}}?>
4.session操作类主要用于拦截未登录用户
<?php session_start(); $user=$_SESSION["username"]; if(empty($user)){ header("Location:../../index.php"); exit(); }?>
- 角色权限管理系统(工具类部分)
- 权限系统--角色管理
- 角色权限管理系统(登录模块)
- 角色权限管理系统(角色功能授权)
- 角色权限管理系统(二级菜单管理)
- RedGlovePermission 权限管理系统源码(支持自定义权限、模块,支持角色权限,用户独立权限以及多角色权限)
- Extjs3.0角色权限管理系统-角色管理模块篇
- 基于角色管理(RBAC)的权限系统
- 基于角色管理(RBAC)的权限系统
- 权限管理系统(4):角色和组
- 基于角色管理(RBAC)的权限系统
- 基于角色管理(RBAC)的权限系统
- 企业信息管理界面雏形(权限管理系统部分)
- 用户、权限、角色(2)- 权限管理
- RDIFramework.NET ━ 9.9 角色权限管理 ━ Web部分
- Extjs3.0角色权限管理系统-用户管理模块篇
- Extjs3.0角色权限管理系统-菜单管理模块篇
- 基于角色的权限管理(转载)
- Xp系统优化 服务相关命令(6)
- 那些年干过的事(二)—成绩查询网站爆库及防护
- 那些年干过的事(三)—系统序列号破解与防护
- C++——CString用法大全
- xml文件的解析
- 角色权限管理系统(工具类部分)
- 那些年干过的事(五)—无源码程序反编译修改文字
- Blocks基础 Using Blocks in iOS 4: The Basics
- 那些年干过的事(六)—无源码修改版本号
- 算法入门3:分支算法(下)
- mysqlbinlog 查看mysql bin 日志
- 第十一周项目2-求最大公约数
- java下载网络数据
- Error when attempting to IMPORT object "MC11VAOHDR_TAB"