class Schema1 protected type null protected source null protected cond

 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
class Schema1 {
protected $type = null;
protected $source = null;
protected $condition = null;
public function select() {
$this->type = 'select';
return $this;
}
public function from($from) {
$this->source = $from;
return $this;
}
public function where($condition) {
$this->condition = $condition;
return $this;
}
public function result() {
// Построение запроса
return $query;
}
}
class Schema2 {
public $type = null;
public $source = null;
public $condition = null;
public function execute() {
if(method_exists($this, $this->type)) {
$method = $this->type;
return $this->$method();
}
}
public function select() {
// Построение запроса
return mysql_query($query);
}
}
class Schema3 {
public function select() {
$query = self::queryBuilder('SELECT', func_get_args());
}
public function create() {
$query = self::queryBuilder('INSERT', func_get_args());
}
public function update() {
$query = self::queryBuilder('UPDATE', func_get_args());
}
public function delete() {
$query = self::queryBuilder('DELETE', func_get_args());
}
protected static function queryBuilder($action, $from) {
// Построение запроса
}
}
class Schema4 {
protected static function queryBuilder($action, $from) {
// Построение запроса
}
public function __call($method, $args) {
$query = self::queryBuilder(strtoupper($method), $args);
$result = self::execute($query);
if(!is_resource($result)) {
return self::wrapData($result);
}
}
}