Location: PHPKode > projects > RabbitBB - Online Web Storage Project > mywebdrive/PHP_CON/user/DAOUserAccount.php
<?PHP
//General DAO
class DAOUserAccount
{
	var $db;
	var $db_table;
	var $db_field;
	
	function DAOUserAccount()
	{
		global $db;
		global $db_table;
		global $db_field;
		$this->db = $db;
		$this->db_table = $db_table;
		$this->db_field = $db_field;
	}

	function getUserbyid($user_id)
	{
		
		//$sqlq = "SELECT * FROM " . $this->db_table['userdb'] . " WHERE user_id=" . $user_id;
		$sqlq = new SQLSelect();
		$sqlq->setSelect($this->db_field['userdb'], $this->db_table['userdb']);
		$sqlq->setWhere($this->db_table['userdb'].".id=$user_id");

		return $this->populate($sqlq->getRow($this->db, $sqlq->SQLReturn()));
	}
	
	function getUserbylogin($username)
	{
		//$sqlq = "SELECT * FROM ".$this->db_table['userdb']." WHERE username='$username'";
		$sqlq = new SQLSelect();
		$sqlq->setSelect($this->db_field['userdb'], $this->db_table['userdb']);
		$sqlq->setWhere($this->db_table['userdb'].".username='".$username."'");
		return $this->populate($sqlq->getRow($this->db, $sqlq->SQLReturn()));
	}

	function populate($_res)
	{
		$tobj = array();
		if (!isset($_res[$this->db_table['userdb']]))
			return $tobj;
		$userres = $_res[$this->db_table['userdb']];
		for ($i=0; $i<count($userres); $i++)
		{
			$tobj[] = $this->createUserAccount($userres[$i]);
		}
		return $tobj;
	}

	function createUserAccount($_row)
	{
		return new UserAccount($_row['id'], $_row['username'], $_row['userpassword'],
			$_row['firstname'], $_row['lastname'], $_row['age'], $_row['gender'],
			$_row['occupation'], $_row['position'], $_row['company'], $_row['email'], $_row['mobile'],
			$_row['addr1'], $_row['addr2'], $_row['balance'], $_row['acctype'],
			$_row['status']);
	}

	function userAccountPopulate($_res)
	{
		$tobj = array();
		if (!isset($_res[$this->db_table['userdb']]))
			return $tobj;
		$userres = $_res[$this->db_table['userdb']];
		for ($i=0; $i<count($userres); $i++)
		{
			$tobj[] = $this->createUserAccount($userres[$i]);
		}
		return $tobj;
	}

}
Return current item: RabbitBB - Online Web Storage Project