All pastes #612303 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-07-10 09:31 UTC
rendered paste body
<?php

class DatabaseFinder extends Database 
{
	public $table;
	
	final public function __construct($table)
	{
		$this->table = "db_{$table}";
	}
	
	/**
	 * Enter description here...
	 *
	 * @param unknown_type $primary_key
	 */
	final public function find($primary_key)
	{
		return $this->findByWhere('id', $primary_key);
	}
	
	/**
	 * Enter description here...
	 *
	 * @param unknown_type $column
	 * @param unknown_type $value
	 */
	final public function findBy($column, $order = 'ASC')
	{
		return $this->query("SELECT * FROM `?` ORDER BY ? ? LIMIT 1", $this->table, $column, $order);
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function findLast()
	{
		return $this->findBy('id', 'DESC');
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function findWhere($column, $value)
	{
		return $this->query("SELECT * FROM `?` WHERE ? = '?' LIMIT 1", $this->table, $column, $value);
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function findAll($order = 'ASC')
	{
		return $this->findAllBy('id', $order);
	}
	
	/**
	 * Enter description here...
	 *
	 * @param unknown_type $column
	 * @param unknown_type $order
	 * @return unknown
	 */
	final public function findAllBy($column, $order = 'ASC')
	{
		return $this->query("SELECT * FROM `?` ORDER BY ? ?", $this->table, $column, $order);
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function findByWhere($column, $value, $order = 'ASC')
	{
		return $this->query("SELECT * FROM `?` WHERE ? = ? ORDER BY ? ? LIMIT 1", $this->table, $column, $value, $column, strtoupper($order));
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function findLastWhere($column, $value)
	{
		return $this->query("SELECT * FROM `?` WHERE ? = '?' ORDER BY id DESC LIMIT 1", $this->table, $column, $value);
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function findAllWhere()
	{
		
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function create()
	{
		
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function drop()
	{
		
	}
	
	/**
	 * Enter description here...
	 *
	 */
	final public function optimize()
	{
		
	}
}

?>