Skip to content

Instantly share code, notes, and snippets.

@mbunge
Created July 26, 2012 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbunge/3182180 to your computer and use it in GitHub Desktop.
Save mbunge/3182180 to your computer and use it in GitHub Desktop.
Trait flavored sqlbuilder (experiment)
<?php
/**
* @author Marco Bunge
* @copyright 2012 Marco Bunge <efika@rubymatrix.de>
*/
abstract class AbstractSqlCommand {
public function build(){
return implode(' ', $this->getCommandElements());
}
}
class SelectCommand extends AbstractSqlCommand {
/**
* Delivers method where
*/
use WhereClause;
public function __construct($table, array $fields){
$this->set('fields',$fields);
$this->set('table',$table);
$cmd[] = 'SELECT';
$cmd[] = $table;
$cmd[] = 'FROM';
$cmd[] = implode(',',$fields);
$this->addCommandElement(implode(' ',$cmd));
}
}
/**
* Where clause trait
*/
trait WhereClause {
public function where(array $conditions, $defaultOperator){
//build conditions
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment