// 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; } }