-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_db.php
89 lines (73 loc) · 2.27 KB
/
student_db.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
<?php
require_once ('db.php');
function add_student ($id, $fields)
{
$sql = 'insert into student (id, fields) values (?, ?)';
$conn = get_connection();
$stm = $conn->prepare($sql);
$stm->bind_param('ss', $id, $fields);
$stm->execute();
if ($stm->affected_rows == 1) {
return $id ;
}
return 0;
}
function update_student_info ($id, $fields)
{
$sql = 'update student set fields = ? id = ?';
$conn = get_connection();
$stm = $conn->prepare($sql);
$stm->bind_param('ss', $fields, $id);
$stm->execute();
if ($stm->affected_rows == 1) {
return 1;
}
if ($stm->affected_rows == 0) {
return 2;
}
return 0;
}
function get_student ($id)
{
$sql = 'select * from student where id = ?';
$conn = get_connection();
$stm = $conn->prepare($sql);
$stm->bind_param('s', $id);
$stm->execute();
if ($stm->execute() == 1) {
$result = $stm->get_result();
$data = $result->fetch_assoc();
if ($data != null) {
return $data;
}
}
return 0;
}
function get_students_infor ()
{
$sql = 'select * from user, student where user.phoneNumber = student.id';
$conn = get_connection();
$result = $conn->query($sql);
$data = array();
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
return $data;
}
function get_search_students($key)
{
$sql = 'select * from student, user where student.id = user.phoneNumber and status = ? and ( fields like ? or user.area like ? or name like ? or phoneNumber like ? or area like ? or gender like ?)';
$conn = get_connection();
$stm = $conn->prepare($sql);
$param = '%' . $key . '%';
$status = 1;
$stm->bind_param('issssss',$status, $param, $param, $param, $param, $param, $param);
$stm->execute();
$result = $stm->get_result();
$data = array();
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
return $data;
}
?>