table('message')."`"; $query = $this->connDB->prepare($sqlString); $query->execute(); $queryResultAll = $query->fetchAll(); return $queryResultAll; } /** * 取得單筆資料 * * @param int $id * @return array */ public function getDataByid($id) { $sqlString = "SELECT * FROM `".$this->table('message')."` WHERE id = :id"; $query = $this->connDB->prepare($sqlString); $query->bindParam(":id", $id); $query->execute(); $queryResultAll = $query->fetch(); return $queryResultAll; } /** * 建立資料 * * @param string $title 標題 * @param string $content 內容 * @return int 建立後的ID */ public function insert($title, $content) { $sqlString = "INSERT INTO `".$this->table('message')."` (title,content) VALUES ( :title, :content )"; $query = $this->connDB->prepare($sqlString); $query->bindParam(":title", $title); $query->bindParam(":content", $content); $query->execute(); return $this->connDB->lastInsertId(); } /** * 編輯 * * @param int $id 編號 * @param string $title 標題 * @param string $content 內容 * @return int 是否有成功 */ public function edit($id, $title, $content) { $sqlString = "UPDATE `".$this->table('message')."` SET content= :content ,title= :title WHERE id= :id"; $query = $this->connDB->prepare($sqlString); $query->bindParam(":id", $id); $query->bindParam(":title", $title); $query->bindParam(":content", $content); $query->execute(); return $query->rowCount(); } public function delete($id) { # code... } }