-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbfunction.php
77 lines (65 loc) · 1.75 KB
/
dbfunction.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
<?php
include 'dbconnection.php';
function insert($data)
{
try {
$con = connect();
$insert = "INSERT INTO `Employees`.`employee` (`id`, `emp_name`, `adress`, `post`) VALUES (NULL, '".$data["emp_name"]."','".$data["adress"]."', '".$data["post"]."')";
$status = mysqli_query($con, $insert);//0 or 1>
} catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
}
return $status;
}
function selectalldata(){
try {
$con = connect();
$selectalldata = "SELECT * from employee";
$result = mysqli_query($con, $selectalldata);//0 or 1>
$row = mysqli_fetch_all($result,MYSQLI_ASSOC);
} catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
}
/*echo "<pre>";
print_r($row);
echo "</pre>";*/
return $row;
}
function delete($id)
{
try {
$con = connect();
$delete = "DELETE FROM `Employees`.`employee` WHERE `employee`.`id` = $id";
$result = mysqli_query($con, $delete);//0 or 1>
} catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
}
/*echo "<pre>";
print_r($row);
echo "</pre>";*/
return $result;
}
function selectbyid($id){
try {
$con = connect();
$selectalldata = "SELECT * from employee where id=$id";
$result = mysqli_query($con, $selectalldata);//0 or 1>
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
} catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
}
return $row;
}
function update($data)
{
try {
$con = connect();
$update = "UPDATE employee SET emp_name = '{$data['emp_name']}', adress = '{$data['adress']}', post = '{$data['post']}' WHERE id = {$data['id']}";
$status = mysqli_query($con, $update);//0 or 1>
} catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
}
var_dump($status);
return $status;
}
?>