<?php
	require_once dirname(__FILE__) . "/dalBase.php";
	class count_lastDAL extends dalBase {
		public $CountID;
		public $IP;
		public $Time;
		public $URL;
		public $RefererURL;
		public $RefererHost;
		public $RefererPath;
		public $RefererQuery;

		public function insertRecord(): bool|int {
			$intoAry = [
				parent::addArray(":ip", $this->IP, "str", 50),
				parent::addArray(":time", $this->Time, "str"),
				parent::addArray(":url", $this->URL, "str", 1000),
				parent::addArray(":refererURL", $this->RefererURL, "str", 1000),
				parent::addArray(":refererHost", $this->RefererHost, "str", 1000),
				parent::addArray(":refererPath", $this->RefererPath, "str", 1000),
				parent::addArray(":refererQuery", $this->RefererQuery, "str", 1000)
			];
			$sql = "INSERT INTO `count_last` (`IP`, `Time`, `URL`, `RefererURL`, `RefererHost`, `RefererPath`, `RefererQuery`)".
				" VALUES (:ip, :time, :url, :refererURL, :refererHost, :refererPath, :refererQuery)";
			$this->data->executeNonQuery($sql, $intoAry, false);
			return (!$this->data->error) ? $this->data->getInsertID() : false;
		}
		//查詢
		public function executeRecordset(array $intoAry = [], string $filter = "", string $order = "", int $start = 0, int $length = -1): array {
			$sql = "SELECT a.* FROM `count_last` a";
			if ($filter !== "") $sql .= " WHERE $filter";
			$sql .= (!isset($order) || $order === "") ? " ORDER BY a.`CountID`" : " ORDER BY $order";
			$length = is_int($length) ? $length : -1;
			return $this->data->executeRecordset($sql, $intoAry, $start, $length);
		}
		//查詢計數
		public function countRecordset(array $intoAry = [], string $filter = ""): int {
			$sql = "SELECT COUNT(*) FROM `count_last` a";
			if ($filter !== "") $sql .= " WHERE $filter";
			return $this->data->executeScalar($sql, $intoAry);
		}
		//刪除
		public function deleteRecord(array $intoAry = [], string $filter = ""): bool {
			$sql = "DELETE FROM `count_last` WHERE $filter";
			$this->data->executeNonQuery($sql, $intoAry, false);
			return (!$this->data->error) ? true : false;
		}
	}
?>