All pastes #621211 Raw Edit

Mine

public text v1 · immutable
·published 2007-07-16 00:53 UTC
rendered paste body
<?php

class DatabaseQuery
{
	public $query;
	
	private function __select($arguments)
	{
		$return = 'SELECT';
		
		if(is_array($arguments)) {
			foreach($arguments as $argument) {
				$return .= " {$argument}, ";
			}
		} else {
			$return .= " {$arguments} ";
		}
		
		return $return;
	}
	
	private function __from($arguments)
	{
		$return = 'FROM';
		
		if(is_array($arguments)) {
			foreach($arguments as $argument) {
				$return .= " {$argument}, ";
			}
		} else {
			$return .= " {$arguments} ";
		}
		
		return $return;
	}
	
	public function __call($method, $arguments)
	{
		$method = "__{$method}";
		$arguments = (isset($arguments[1])) ? $arguments : $arguments[0];
		
		$this->query .= $this->$method($arguments);
		
		return $this;
	}
	
	public function __toString()
	{
		return $this->query;
	}
}

$db = new DatabaseQuery();

echo $db->select('id', 'username', 'password')->from('users')->where('user_id = 5')->limit(1);

?>