-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainCategory.php
executable file
·76 lines (65 loc) · 1.66 KB
/
mainCategory.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
<?php
class MainCategory
{
private static $conn = Null;
function __construct($id=-1)
{
if(self::$conn == Null)
{
self::$conn = mysqli_connect('localhost','root','iti','clothes_shop');
}
if($id!=-1)
{
$query = "select * from category where id=$id limit 1";
$result = mysqli_query(self::$conn,$query);
$mainCategory = mysqli_fetch_assoc($result);
$this->id = $mainCategory['id'];
$this->type = $mainCategory['type'];
}
}
function if_exist()
{
//echo $this->type;
$query = "select * from category where type='$this->type' limit 1";
$result = mysqli_query(self::$conn,$query);
//echo mysqli_num_rows($result);
return mysqli_num_rows($result);
}
function getIdCategory()
{
$query = "select id from category where type='$this->type'";
$result = mysqli_query(self::$conn,$query);
return mysqli_fetch_assoc($result);
}
function removeMainCategory()
{
$query = "delete from category where type='$this->type'";
$result = mysqli_query(self::$conn,$query);
return mysqli_affected_rows($result);
}
function insertMainCategory()
{
// echo $this->type;
$query = "insert into category values(null,'$this->type')";
$result = mysqli_query(self::$conn,$query);
return mysqli_insert_id(self::$conn);
}
function getMainCategory()
{
$query = "select * from category";
$result = mysqli_query(self::$conn,$query);
$data = [];
while($row = mysqli_fetch_assoc($result))
{
$data[] = $row;
}
return $data;
}
function updateMainCategory()
{
$query = "update category set type='$this->type' where id='$this->id'";
$result=mysqli_query(self::$conn,$query);
return mysqli_affected_rows($result);
}
}
?>