Location: PHPKode > scripts > DbCodeBuilder > dbcodebuilder/result/User.dao.php
<?php
require_once('User.vo.php');
/**
 *
 */
class UserDAO
{
	/**
	 * Enter description here...
	 *
	 * @var unknown_type
	 */
	private $link;



	/**
	 * Enter description here...
	 *
	 * @param unknown_type $link
	 */
	public function __construct($link)
	{
		$this -> link = $link;
	}



	/**
	 * Enter description here...
	 *
	 * @param unknown_type $vo
	 */
	public function save($vo)
	{
		if ($vo->getId() == 0)
		{
			$this->insert($vo);
		}
		else
		{
			$this->update($vo);
		}
	}



	/**
	 * Enter description here...
	 *
	 * @param Integer $id
	 * @return unknown_type
	 */
	public function get($id)
	{
		$sql = 'SELECT * FROM user WHERE id = ' . $id;
		$query = mysql_query($sql, $this->link);
		$result = mysql_fetch_assoc($query);
		$vo = new UserVO();
		$this->getFromResult($vo, $result);
		return $vo;
	}



	/**
	 * Enter description here...
	 *
	 * @param unknown_type $vo
	 */
	public function delete($vo)
	{
		$sql = 'DELETE FROM user WHERE id = ' . $vo->getId();
		$result = mysql_query($sql, $this->link);
		$vo->setId(0);
	}



	/**
	 * Enter description here...
	 *
	 * @param unknown_type $vo
	 * @param unknown_type $result
	 */
	private function getFromResult($vo, $result)
	{
		$vo->setId($result['id']);
		$vo->setUsername($result['username']);
		$vo->setPassword($result['password']);
		$vo->setRank($result['rank']);
		$vo->setActive($result['active']);
	}



	/**
	 * Enter description here...
	 *
	 * @param unknown_type $vo
	 */
	private function update($vo)
	{
		$sql = 'UPDATE user SET id = \''.$vo->getId().'\', username = \''.$vo->getUsername().'\', password = \''.$vo->getPassword().'\', rank = \''.$vo->getRank().'\', active = \''.$vo->getActive().'\' WHERE id = \''.$vo->getId().'\'';
		mysql_query($sql, $this->link) or die (mysql_error());
	}



	/**
	 * Enter description here...
	 *
	 * @param unknown_type $vo
	 */
	private function insert($vo)
	{
		$sql = 'INSERT INTO user (username, password, rank, active) VALUES (\''.$vo->getUsername().'\', \''.$vo->getPassword().'\', \''.$vo->getRank().'\', \''.$vo->getActive().'\')';
		mysql_query($sql, $this->link) or die (mysql_error());
		$vo->setId(mysql_insert_id());
	}
}
?>
Return current item: DbCodeBuilder