Role Rights Management System (part of Tool Class)
Source: Internet
Author: User
In order to better develop, this project I wrote a few more useful tool classes mainly around the database operation, pagination, session to get a look at it 1. Database connection Tools [PHP] <?php & nbsp Class dbutil{ private $host = "localhost"; private $username = "root"; & nbsp private $password = "123456"; private $dbname = "Humanresource"; private $conn; public function Dbutil () { $this->conn=new Mys Qli ($this->host, $this->username, $this->password, $this->dbname) or Die ($this->conn->connect_ Error);  , public function getconnection () { return $this->conn; &NBSP} public function Close () { if ($this->c Onn) { $this->conn->close (); { } } ?> This class is mainly used for Get or close the database connection 2. Database operation class [PHP] <?php class Basedboperate { &NBSP;PUBL IC function Query ($sql, $conn) { //Set query encoding, my local database code is 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; &NBSP} public function otheroperate ($sql, $conn{ $conn->query ("Set names UTF8") if ($conn->query ($sql)) { & nbsp if ($conn->affected_rows>0) { return "1"; }else{ return "0"; { } //paging query   ; 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; &nbs P } $result->free (); //Get the display data required for pagination &nbsP $fenyePage->fenyearray = $arr; //Get total data rows $res 2 = $conn->query ($totalPageSql) or Die ($this->conn->err OR); if ($rows = $res 2->fetch_row ()) { //Get total pages $fenyePage->sumpage = ceil ($rows [0]/$fenyePage->everypagerows); } //Free resources $res 2->free (); &NBSP, //cycle Delete data function Loopdelete ($sqls, $conn) { $conn->query ("Set names UTF8") $temp =0; &nbs P $flag = "0"; for ($i =0 $i <count ($SQLS) $i + +) { if ($conn->query ($sqls [$i] ) { if ($conn->affected_rows>0) { &NBSP $temp + +; { &NBS P if ($temp >0) { $flag = "1"; }else{ &NBS P $flag = "0"; } return $flag; &NBSP} } ?> 3. Relatively simple paging components, although a little flaw but still very easy to use [php] PHP class Fenyepage { public $everyPageRows;//per page shows the number of lines public $sumPage; /Total pages public $nowPage; Current page public $fenyeArray; Data displayed on pagination public $navigate; Pagination navigation bar public $pageWhole; Page pages public $url; Page pages function shownavigate () { echo "<ul class= ' Fenye_ul ' > "; echo "<a href= ' $this->url&nowpage=1 ' ><li> home </li ></a> "; if ($this->nowpage > 1) { Echo <a href= ' $this->url&nowpage= '. ($this->nowpage-1). "' ><li class= ' btn ' > Prev </li></a>"; { //page out , $startPage = Floor (($this->nowpage-1)/$this->pagewhole) * $this->pagewhole + 1; $index = $startPage; //If the current page is between 1 and 10, there is no need to display the link to page forward if ($this->nowpage > $this->pagewhole) { echo "<a href= ' $this->url&nowpage= " . ($startPage-1). "' ><li><b><<</b></li></a>"; &NBsp for (; $startPage < $index + $this->pagewhole; $startPage + +) { &N Bsp if ($startPage = = $this->nowpage) { echo "<a href= ' $this->url&nowpage= $startPage ' ><li style= ' background: #6699cc; ' > $startPage </li></a> "; } else { E Cho "<a href= ' $this->url&nowpage= $startPage ' ><li> $startPage </li></a>"; I If the value of StartPage is less than the total number of pages, display backwards translation if ($startPage < $this->sumpage) { & nbsp echo "<a href= ' $this->url&nowpage= $startPage ' ><li><b>>> </b></li&gT;</a> "; $this if (->nowpage < $this->sumpage) {&N Bsp echo "<a href= ' $this->url&nowpage=". ($this->nowpage + 1). "' ><li> next page </li></a>"; { Echo A href= ' $this->url&nowpage={$this->sumpage} ' ><li> last </li></a> '; echo "<li> total {$this->sumpage} page </li>"; echo "</ul>"; } } ?> 4.session operation class is primarily used to intercept logged-in users [PHP] <?php SES Sion_start (); $user =$_session["username"]; if (empty ($user)) { header ("Location:.. /.. /index.php "); exit (); } ?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service