-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory_sql.php
More file actions
67 lines (54 loc) · 1.63 KB
/
category_sql.php
File metadata and controls
67 lines (54 loc) · 1.63 KB
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
<?php
function getAllCategory() {
global $servername, $username, $password, $dbname;
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) die("Connection failed: " . mysqli_connect_error());
$sql = "SELECT * FROM category";
$result = mysqli_query($conn, $sql);
$arary;
if (mysqli_num_rows($result) > 0) {
while($data = mysqli_fetch_assoc($result)) {
// echo "id: " . $data["id"]. " - name: " . $data["name"]. "<br>";
$arary[] = $data;
}
}
mysqli_close($conn);
return ($arary);
}
function putCategory ($name) {
global $servername, $username, $password, $dbname;
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) die("Connection failed: " . mysqli_connect_error());
$sql = "INSERT INTO category (name) VALUES ('$name')";
$res = false;
if (mysqli_query($conn, $sql)) {
$res = true;
}
mysqli_close($conn);
return ($res);
}
function deleteCategory ($id) {
global $servername, $username, $password, $dbname;
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) die("Connection failed: " . mysqli_connect_error());
$sql = "DELETE FROM category WHERE id='$id'";
$res = false;
if (mysqli_query($conn, $sql)) {
$res = true;
}
mysqli_close($conn);
return ($res);
}
function updateCategory ($id, $name) {
global $servername, $username, $password, $dbname;
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) die("Connection failed: " . mysqli_connect_error());
$sql = "UPDATE category SET name='$name' WHERE id='$id'";
$res = false;
if (mysqli_query($conn, $sql)) {
$res = true;
}
mysqli_close($conn);
return ($res);
}
?>