-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_unit.php
105 lines (89 loc) · 2.17 KB
/
class_unit.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
require_once("class_database.php");
/**
*
*/
class unit
{
private $id;
private $name;
private $otherUnit;
private $quantity;
private $gQuantity;
private $gPerOU;
// 方法
// __get(): 获取属性值
function __get($property_name){
if (isset($property_name)){
return $this->$property_name; // 这里的 property_name 前必须加 $ 否则 错误!
}else{
return null;
}
}
// __set(): 设置属性值
function __set($property_name, $value){
$this->$property_name=$value; // 这里的 property_name 前必须加 $ 否则 错误!
}
function __construct()
{
# code...
}
// addnew
function addnew(){
$db = new database;
$sql = "INSERT INTO units (name,otherUnit,quantity,gQuantity,gPerOU)";
$sql .= " VALUES ('$this->name','$this->otherUnit','$this->quantity','$this->gQuantity','$this->gPerOU')";
// echo $sql;
$db->execute($sql);
$db=null;
}
function update(){
$db = new database;
$sql = "UPDATE units SET ";
$sql .= "name='$this->name', otherUnit='$this->otherUnit',quantity='$this->quantity',gQuantity='$this->gQuantity',gPerOU='$this->gPerOU'";
$sql .= " where id=$this->id";
$db->execute($sql);
$db=null;
}
// query by id
function query(){
$db = new database;
$sql = "SELECT * FROM units ";
$sql .= " WHERE id =$this->id";
$unit = $db->executeSFOR($sql);
$db=null;
return $unit;
}
// queryAll
function queryAll(){
$db = new database;
$sql = "SELECT *FROM units";
$arr_units = $db->query($sql);
$db=null;
return $arr_units;
}
// queryRowsNum
function queryRowsNum(){
$db = new database;
$sql = "SELECT *FROM units";
$rowsNum = $db->queryRows($sql);
$db = null;
return $rowsNum;
}
// delete by id
function delete(){
$db = new database;
$sql = "DELETE FROM units where id=$this->id";
$db->execute($sql);
$db = null;
}
// query now
function queryNow(){
$db = new database;
$sql = "SELECT *FROM units where name like '%$this->name%' and otherUnit like '%$this->otherUnit%' and quantity like '%$this->quantity%'";
$arr_units = $db->query($sql);
$db=null;
return $arr_units;
}
}
?>