table('user_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('user_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"); } }