-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlHelper.class.php
96 lines (84 loc) · 2.47 KB
/
SqlHelper.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016/1/15 0015
* Time: 下午 4:29
*/
class SqlHelper
{
public $conn;
public $dbname = "empmanage";
public $username="root";
public $password="090324";
public $host="localhost";
public function __construct()
{
$this->conn =mysqli_connect($this->host, $this->username, $this->password, $this->dbname);
if (mysqli_connect_error()) {
die("连接失败!".mysqli_connect_error());
exit();
}
}
public function execute_dql($sql)
{
$res = mysqli_query($this->conn, $sql);
return $res;
}
public function execute_dql2($sql){
$arr = array();
$res = mysqli_query($this->conn,$sql) or die(mysqli_error($this->conn));
while($row = mysqli_fetch_assoc($res)){
$arr[] =$row;
}
mysqli_free_result($res);
return $arr;
}
/**
* @param $sql1 ="select * from where tablename limit ...."
* @param $sql2 ="select count(id) from tableName"
* @param $fenyePage
*/
public function exectue_dql_fenye($sql1,$sql2,$fenyePage){
$res = mysqli_query($this->conn,$sql1);
$arr = array();
while($row = mysqli_fetch_assoc($res)){
$arr[] = $row;
}
mysqli_free_result($res);
$res =mysqli_query($this->conn,$sql2);
if($row = mysqli_fetch_row($res)){
$fenyePage->pageCount = ceil($row[0]/$fenyePage->pageSize);
$fenyePage->rowCount =$row[0];
}
mysqli_free_result($res);
$navigate= "";
if($fenyePage->pageNow>1){
$prePage=$fenyePage->pageNow-1;
$navigate="<a href='empList.php?pageNow=$prePage'> 上一页 </a>";
}
if($fenyePage->pageNow<$fenyePage->pageCount){
$nextPage=$fenyePage->pageNow+1;
$navigate.="<a href='empList.php?pageNow=$nextPage'> 下一页 </a>";
}
$fenyePage->res_array = $arr;
$fenyePage->navigate = $navigate;
}
public function execute_dml($sql){
$b = mysqli_query($this->conn,$sql);
if(!$b){
return 0;
} else{
if(mysqli_affected_rows($this->conn)>0){
return 1;
} else{
return2;
}
}
}
public function close_conn(){
if(!empty($this->conn)){
mysqli_close($this->conn);
}
}
}