-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
65 lines (43 loc) · 1.07 KB
/
functions.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
<?php
require_once 'config.php';
session_start();
/*验证是否登录*/
function current_manager(){
if (empty($_SESSION['current_login_manager'])) {
header('Location:/MrWhite/admin/login.php');
exit();
}
return $_SESSION['current_login_manager'];
};
/*数据库查询功能*/
function white_fetch_all($sql){
$conn=mysqli_connect(WHITE_DB_HOST,WHITE_DB_USER,WHITE_DB_PASS,WHITE_DB_NAME);
if (!$conn) {
exit('数据库连接失败');
}
$query=mysqli_query($conn,$sql);
while ($row=mysqli_fetch_assoc($query)) {
$result[]=$row;
}
mysqli_free_result($query);
mysqli_close($conn);
return $result;
}
/*从数据库查询一条数据*/
function white_fetch_one($sql){
$row=white_fetch_all($sql)[0]?white_fetch_all($sql)[0]:null;
return $row;
}
/*执行数据库执行语句*/
function white_fetch_excute($sql){
$conn=mysqli_connect(WHITE_DB_HOST,WHITE_DB_USER,WHITE_DB_PASS,WHITE_DB_NAME);
if (!$conn) {
exit('数据库连接失败');
}
$query=mysqli_query($conn,$sql);
if(!$query){
return;
}
$rows=mysqli_affected_rows($conn);
return $rows;
}