<?php
	require_once dirname(__FILE__)."/dalBase.php";
	class autokeywordlinkDAL extends dalBase{
		public $ID;
		public $KeywordID;
		public $LinkURL;
		public $Visible = 1;
		public $OrderNO = 0;

		public function loadRecord(){
			$sql = "SELECT a.* FROM `autokeywordlink` a WHERE a.`ID`='".$this->ID."'";

			$reader = $this->data->executeReader($sql);
			$this->ID = $reader["ID"];
			$this->KeywordID = $reader["KeywordID"];
			$this->LinkURL = $reader["LinkURL"];
			$this->Visible = $reader["Visible"];
			$this->OrderNO = $reader["OrderNO"];

			if(!$this->data->error)
				return true;
			return false;
		}
		public function insertRecord(){
			$sql = "INSERT INTO `autokeywordlink` (`KeywordID`,`LinkURL`,`Visible`,`OrderNO`) VALUES (@KeywordID,@LinkURL,@Visible,@OrderNO)";
			$sql = str_replace("@KeywordID","'".$this->KeywordID."'",$sql);
			$sql = str_replace("@LinkURL","'".$this->LinkURL."'",$sql);
			$sql = str_replace("@Visible","'".$this->Visible."'",$sql);
			$sql = str_replace("@OrderNO","'".$this->OrderNO."'",$sql);

			$this->data->executeNonQuery($sql);
			if(!$this->data->error)
				return $this->data->getInsertID();
			return false;
		}
		public function updateRecord(){
			$sql = "UPDATE `autokeywordlink` SET " .
				"`LinkURL`=@LinkURL" .
				",`Visible`=@Visible" .
				",`OrderNO`=@OrderNO" .
				" WHERE `ID`=@ID";
			$sql = str_replace("@ID","'".$this->ID."'",$sql);
			$sql = str_replace("@LinkURL","'".$this->LinkURL."'",$sql);
			$sql = str_replace("@Visible","'".$this->Visible."'",$sql);
			$sql = str_replace("@OrderNO","'".$this->OrderNO."'",$sql);

			$this->data->executeNonQuery($sql);
			if(!$this->data->error)
				return true;
			return false;
		}
		//查詢
		public function executeRecordset($filter="",$order="",$start=0,$length=-1){
			$sql = "SELECT a.* FROM `autokeywordlink` a";
			if(trim($filter) != "")
				$sql .= " WHERE ".$filter;
			if(!isset($order) || $order == "")
				$sql .= " ORDER BY a.`OrderNO`";
			else
				$sql .= " ORDER BY ".$order;
			return $this->data->executeRecordset($sql,$start,$length);
		}
		//查詢計數
		public function countRecordset($filter=""){
			$sql = "SELECT COUNT(*) FROM `autokeywordlink` a";
			if($filter != "")
				$sql .= " WHERE ".$filter;

			return $this->data->executeScalar($sql);
		}

		//刪除
		public function deleteRecord($id){
			$sql = "DELETE FROM `autokeywordlink` WHERE `ID`='".$id."'";
			$this->data->executeNonQuery($sql);

			if(!$this->data->error)
				return true;
			return false;
		}
	}
?>