commit b76905eb2857061361f5b1bc0753963fbadca265 Author: Yuan Chiu Date: Sat Apr 4 18:17:47 2020 +0800 init diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..73c5516 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8982778 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +htdocs/config.php \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..04063a8 --- /dev/null +++ b/Readme.md @@ -0,0 +1,22 @@ +JGB Yuan 練習作業 +=== +# 安裝方法 +待補充 + +# 檔案結構 + +* index.php 列表(包含分頁) +* edit.php 編輯 +* view.php 瀏覽 + +# 題目要求 +下週五code review的小作業:請使用原生寫法(不得使用任何框架),用 html + css + php + mysql 寫出簡易的留言版系統 + +要求: +1. 有列表,帶分頁(分頁形式不拘) +2. 新增/編輯/刪除留言功能 +3. 資料存在MySQL +4. css盡量使用,畫面別太醜 + + +本機沒環境的話,請裝xampp for mac \ No newline at end of file diff --git a/htdocs/.DS_Store b/htdocs/.DS_Store new file mode 100644 index 0000000..db56aec Binary files /dev/null and b/htdocs/.DS_Store differ diff --git a/htdocs/config.sample.php b/htdocs/config.sample.php new file mode 100644 index 0000000..c77ea79 --- /dev/null +++ b/htdocs/config.sample.php @@ -0,0 +1,57 @@ + 1, + 'title' => 'text', + 'updated_at' => '2020-04-01 12:13', + ], + [ + 'id' => 2, + 'title' => 'text', + 'updated_at' => '2020-04-01 12:13', + ], +]; + +?> + + + + + + + Document + + +
+

留言板

+
+
+
+ +
+
+ + 0) { + echo ' + + + + + + + + + + + '; + + foreach ($list as $key => $item) { + echo ' + + + + + + + '; + } + + echo ' + +
idtitleupdated_ataction
idtitleupdated_at + +
+ '; + } + else { + echo '無資料'; + } + ?> +
+
+ + \ No newline at end of file diff --git a/htdocs/lib/.DS_Store b/htdocs/lib/.DS_Store new file mode 100644 index 0000000..d37bde2 Binary files /dev/null and b/htdocs/lib/.DS_Store differ diff --git a/htdocs/lib/Database/Database.php b/htdocs/lib/Database/Database.php new file mode 100644 index 0000000..bd77b4a --- /dev/null +++ b/htdocs/lib/Database/Database.php @@ -0,0 +1,151 @@ + 'mysql', + * 'host' => 'localhost', + * 'port' => '3306', + * 'user' => 'user', + * 'password' => '123456', + * 'dbname' => 'chu-elearning', + * 'prefix' => 'chu_' + * )); + * + * 實際範例可參考 `DBAdmin` 類別的說明文件 + * + * @author Yuan Chiu + * @version 2.0.0 + * @subpackage Database + */ +abstract class Database { + + /** + * 資料庫伺服器位址 + * @type string + */ + protected $db_host; + + /** + * 資料庫伺服器連結埠 + * @type string + */ + protected $db_port; + + /** + * 資料庫帳號 + * @type string + */ + protected $db_user; + + /** + * 資料庫密碼 + * @type string + */ + protected $db_passwd; + + /** + * 資料庫名稱 + * @type string + */ + protected $db_name; + + /** + * 資料表前綴字元 + * @type string + */ + protected $db_prefix; + + // ------------------------------------------------------------------------ + + /** + * 資料庫連結物件 + */ + protected $connDB; + + // ======================================================================== + + /** + * 連接資料庫 + * + * @param array $conf (optional) 資料庫相關參數,格式為: + * array( 'type' => 'mysql', + * 'host' => 'localhost', + * 'port' => '3306', + * 'user' => 'user', + * 'password' => '123456', + * 'dbname' => 'chu-elearning', + * 'prefix' => 'chu_' ) + * 若不填寫將會直接使用設定在`config.php`的常數 + * + * @throws MessageBoard\Exception\DatabaseNoSupportException + * @author Yuan Chiu + * @since 2.0.0 + */ + public function __construct($conf = null) { + + // 將資料庫設定資訊帶入 + if(isset($conf)) { + $this->db_host = $conf['host']; + $this->db_port = $conf['port']; + $this->db_user = $conf['user']; + $this->db_passwd = $conf['password']; + $this->db_name = $conf['dbname']; + $this->db_prefix = $conf['prefix']; + } + else { + $this->db_host = DB_HOST; + $this->db_port = DB_PORT; + $this->db_user = DB_USER; + $this->db_passwd = DB_PASS; + $this->db_name = DB_NAME; + $this->db_prefix = DB_PREFIX; + } + + $this->connDB = new MySQLDB($this->db_name + , $this->db_host + , $this->db_port + , $this->db_user + , $this->db_passwd); + } + + /** + * 轉為完整的資料表名稱(包含前綴字元) + * + * @param string $tableName 資料表名稱 + * @return string 完整的資料表名稱 + * + * @author Yuan Chiu + * @since 2.0.0 + */ + public function table($tableName) { + return $this->db_prefix.$tableName; + } + + /** + * 測試資料庫有無連接成功 + * + * @since 2.0.0 + */ + public function connectTest() { + // TODO: Fill code in + + } +} diff --git a/htdocs/lib/Database/DbMessage.php b/htdocs/lib/Database/DbMessage.php new file mode 100644 index 0000000..3014cf8 --- /dev/null +++ b/htdocs/lib/Database/DbMessage.php @@ -0,0 +1,104 @@ +table('user')."` AS `user` ". + "LEFT JOIN `".$this->table('user_auth_group')."` as `group` ". + "ON `group`.`GID` = `user`.`GID`". + "LEFT JOIN `".$this->table('user_class')."` as `class` ". + "ON `class`.`CID` = `user`.`CID`". + "WHERE ".$where; + + $query = $this->connDB->prepare($sqlString); + $query->execute(); + + $queryResultAll = $query->fetchAll(); + + return $queryResultAll; + // // 如果有查到一筆以上 + // if( count($queryResultAll) >= 1 ) { + // // 製作回傳結果陣列 + // $result = array(); + // foreach($queryResultAll as $key => $thisResult) { + + // if($thisResult['UEnabled'] != '0') { + // $output_enable = true; + // } + // else { $output_enable = false; } + + // if($thisResult['UEnable_NoAppoint'] != '0') { + // $output_enable_noAppoint = true; + // } + // else { $output_enable_noAppoint = false; } + + // array_push($result, + // array( 'user_id' => $thisResult['UID'], + // 'password' => $thisResult['UPassword'], + // 'group_id' => $thisResult['GID'], + // 'group_name' => $thisResult['GName'], + // 'class_id' => $thisResult['CID'], + // 'class_name' => $thisResult['CName'], + // 'enable' => $output_enable, + // 'build_time' => $thisResult['UBuildTime'], + // 'modify_time' => $thisResult['UModifyTime'], + // 'learnStyle_mode' => $thisResult['LMode'], + // 'material_mode' => $thisResult['MMode'], + // 'enable_noAppoint' => $output_enable_noAppoint, + // 'nickname' => $thisResult['UNickname'], + // 'realname' => $thisResult['URealName'], + // 'email' => $thisResult['UEmail'], + // 'memo' => $thisResult['UMemo']) + // ); + // } + // return $result; + // } + // else { + // return null; + // } + } + + public function insert(Type $var = null) + { + # code... + } + + public function edit() + { + # code... + } + + public function delete($id) + { + # code... + } +} \ No newline at end of file diff --git a/htdocs/lib/Database/MySQLDB.php b/htdocs/lib/Database/MySQLDB.php new file mode 100644 index 0000000..f789c21 --- /dev/null +++ b/htdocs/lib/Database/MySQLDB.php @@ -0,0 +1,69 @@ + + * @version 2.0.0 + * @see https://github.com/shuliu/myPDO + * @subpackage Database + */ +class MySQLDB extends PDO { + + /** + * 連結資料庫 + * + * @param string $dbname 資料庫名稱 + * @param string $host 資料庫伺服器位址 + * @param int $port 資料庫伺服器連接埠 + * @param string $user 資料庫伺服器帳號 + * @param string $passwd 資料庫伺服器密碼 + * @author Yuan Chiu + * @since 2.0.0 + */ + public function __construct($dbname, $host, $port, $user, $passwd){ + parent::__construct('mysql:dbname='.$dbname + .';host='.$host.';port='.$port + .';charset=utf8', DB_USER, DB_PASS); + + //配合PHP< 5.3.6 PDO沒有charset用的 + //參考: http://gdfan1114.wordpress.com/2013/06/24/php-5-3-6-%E7%89%88-pdo-%E9%85%8D%E5%90%88%E5%AD%98%E5%8F%96%E8%B3%87%E6%96%99%E5%BA%AB%E6%99%82%E7%9A%84%E4%B8%AD%E6%96%87%E5%95%8F%E9%A1%8C/ + $this->exec('set names utf8'); + } + + // ======================================================================== + /** + * 錯誤訊息的陣列 + * + * 改寫Adodb -> ErrorMsg + * + * @access public + * @return array 錯誤訊息 + * + * @since 2.0.0 + * @author shuliu + * @see https://github.com/shuliu/myPDO/blob/master/PDO.class.php + */ + public function errorMsg(){ + $err = parent ::errorinfo(); + if( $err[0]!='00000' ){ + return array('errorCode'=>$err[0] + ,'number'=>$err[1] + ,'message'=>$err[2]); + }else{ + return null; + } + } + + }