diff --git a/htdocs/lib/Database/DBLog.php b/htdocs/lib/Database/DBLog.php new file mode 100644 index 0000000..d23ef6c --- /dev/null +++ b/htdocs/lib/Database/DBLog.php @@ -0,0 +1,130 @@ +table('Log'). + " (`LID`, `UID`, `Date`, `SaID`, `TID`, + `ActionGroup`, `Encode`, + `QID`, `Aswer`, `Other`) + VALUES ( :lid , :uid, :date , :said , :tid , + :actionGruop , :encode , :qid , + :answer , :other )"; + + $query = $this->connDB->prepare($sqlString); + $query->bindParam(":lid", $LID); + $query->bindParam(":uid", $UId); + $query->bindParam(":date", $Date); + $query->bindParam(":said", $SaID); + $query->bindParam(":tid", $TID); + $query->bindParam(":actionGruop", $ActionGruop); + $query->bindParam(":encode", $Encode); + $query->bindParam(":qid", $QID); + $query->bindParam(":answer", $Answer); + $query->bindParam(":other", $Other); + $query->execute(); + + } + + /** + * 內部使用的查詢動作 + * @param string $where 查詢語法 + * @return array 查詢結果陣列 + */ + protected function queryLogByWhere($where) { + + $sqlString = "SELECT * FROM `".$this->table('Log')."` ". + "WHERE ".$where; + + $query = $this->connDB->prepare($sqlString); + $query->execute(); + + $queryResultAll = $query->fetchAll(); + // 如果有查到一筆以上 + if( count($queryResultAll) >= 1 ) { + // 製作回傳結果陣列 + $result = array(); + foreach($queryResultAll as $key => $thisResult) { + + array_push($result, + array( 'lid' => $thisResult['LID'], + 'uid' => $thisResult['UID'], + 'date' => $thisResult['Date'], + 'said' => $thisResult['SaID'], + 'tid' => $thisResult['TID'], + 'actionGruop' => $thisResult['ActionGroup'], + 'encode' => $thisResult['Encode'], + 'qid' => $thisResult['QID'], + 'answer' => $thisResult['Aswer'], + 'other' => $thisResult['Other'] + ) + ); + } + return $result; + } + else { + return null; + } + } + + public function queryLog($lid) { + + $queryResultAll = $this->queryLogByWhere("`LID`=".$this->connDB->quote($lid)); + + // 如果有查到一筆以上 + if( count($queryResultAll) >= 1 ) { + return $queryResultAll[0]; + } + // 若都沒查到的話 + else { + return null; + } + } + + public function queryAllLog() { + return $this->queryLogByWhere("1"); + } +} diff --git a/sql/UElearning.sql b/sql/UElearning.sql index 3d877e1..1fe1c3f 100644 --- a/sql/UElearning.sql +++ b/sql/UElearning.sql @@ -377,9 +377,15 @@ CREATE TABLE IF NOT EXISTS `chu__Log` ( `LID` int(11) NOT NULL AUTO_INCREMENT, `UID` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `Date` datetime NOT NULL, + `SaID` int(10) DEFAULT NULL, + `TID` int(10) DEFAULT NULL, + `ActionGroup` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Encode` varchar(3) COLLATE utf8_unicode_ci NOT NULL, + `QID` int(10) DEFAULT NULL, + `Aswer` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, + `Other` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`LID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ; -- --------------------------------------------------------