Schema Schema1 new Schema1 Schema1_result Schema1- select from my_tabl

  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
// Schema 1
$Schema1 = new Schema1();
$Schema1_result = $Schema1->select()->from('my_table')->where('age > 18')->result();
// Schema 2
$Schema2 = new Schema2();
$Schema2->type = 'SELECT';
$Schema2->source = 'my_table';
$Schema2->condition = 'age > 18';
// Schema 3
$result = Schema3::getInstance()->select($from = 'my_table', $condition= 'age > 18');
// Schema 4
$result = Schema4::getInstance()->select($from = 'my_table', $condition= 'age > 18');
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 mysql_query($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);
}
return $result;
}
}