All pastes #759114 Raw Edit

DBObject

public php v1 · immutable
·published 2007-11-02 21:07 UTC
rendered paste body
<?phpclass DBObject{	public $TABLE_NAME;	public $list;	private $count;		public static function transformId($id = 0)	{		/*			if it's just a number, add id =			otherwise, return same		*/				return (is_numeric($id)) ? "id=".$id : $id;	}		function __construct($tablename, $where = 0, $limit = 0, $variables = "*")	{		// Automatic Loading		// ************************************************		$this->TABLE_NAME = $tablename;				if ($where || $load)		{			return $this->load($where, $limit, $variables);		}		else		{			return false;		}	}		function load($where = "(1)", $limit = 0, $variables = "*")	{		/******************************************\				    Load Into DBObject		\******************************************/				// Build Query		// *****************************************		$query = "SELECT " . $variables . " FROM " . $this->TABLE_NAME . " WHERE " . $where;		if ($limit)		{ $query = $query . " LIMIT " . $limit; }				// Get all rows returned		// *****************************************		// D("$query", NOTICE);				$result = mysql_query($query);		if (!$result)		{			Debug::Out("Invalid Query?: ".$query, ERROR);			return false;		}				// Load Field Names		// *****************************************		$fields;		$numberfields = mysql_num_fields($result);		for ($n = 0; $n < $numberfields; $n++)		{ $fields[$n] = mysql_field_name($result, $n); }				// Get array of it		// *****************************************		$i = 0;				while ($row = mysql_fetch_array($result))		{			$this->list[$i] = new DBWriteObject($this->TABLE_NAME, $fields);			for ($n = 0; $n < $numberfields; $n++)			{ $this->list[$i]->$fields[$n] = $row[$n];	}			$i++;		}	}}?>