From b76905eb2857061361f5b1bc0753963fbadca265 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Sat, 4 Apr 2020 18:17:47 +0800 Subject: [PATCH] init --- .editorconfig | 8 ++ .gitignore | 1 + Readme.md | 22 +++++ htdocs/.DS_Store | Bin 0 -> 6148 bytes htdocs/config.sample.php | 57 +++++++++++ htdocs/css/here | 0 htdocs/index.php | 83 ++++++++++++++++ htdocs/lib/.DS_Store | Bin 0 -> 6148 bytes htdocs/lib/Database/Database.php | 151 ++++++++++++++++++++++++++++++ htdocs/lib/Database/DbMessage.php | 104 ++++++++++++++++++++ htdocs/lib/Database/MySQLDB.php | 69 ++++++++++++++ 11 files changed, 495 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 Readme.md create mode 100644 htdocs/.DS_Store create mode 100644 htdocs/config.sample.php create mode 100644 htdocs/css/here create mode 100644 htdocs/index.php create mode 100644 htdocs/lib/.DS_Store create mode 100644 htdocs/lib/Database/Database.php create mode 100644 htdocs/lib/Database/DbMessage.php create mode 100644 htdocs/lib/Database/MySQLDB.php 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 0000000000000000000000000000000000000000..db56aec0327b7820876073a34b593eadd2d23526 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8ZYW|7f<5Nqt%nw^!GjQDJ$Mr$dQfQ-Qfwe5rAaLsD|rolBcH(6 zab|Zb7JKj{VrO9Yo7tJ!&3uskVT^Hi61EvL8Djz(B1dJ3;P6scMF%5toFf|raT*c3P3Fr9k2pHDK^A77z$=I6se z>*r}2f9ig45e=q2bNe_=az9E2W0@R<0|>dkjFK>&y6GedGdYi^9EM>Cqh~gXqGNZO z*1ml>Yg&bEw?N-Jn9U5av)ev8?cY5-7EiP17sW3J`lW1XoWm<9y1aXDoWyBz3nTOB zc@!ZrKnxHA#K1~1ppOAjU#Y68SYm(}_z45JKUmNZ9gU?zxphE?*Jt$C5K%zKw*;c4 z(a~5c1P=&Tseme#>n8?R=`e2TI7eftP^B|2SB81?%Jatym#f3LCBqqa6jDzN5Ce-0 zRF!Gs`F{ex%+g2xVhUNr05R~-7~r+8*L9&NeYSop56@Z)S|1t;#+9gmfWB}E00Z}t fhIA^wg*wDJ8cT&Z3y#ZlK)MJ>LZ~AKeu04x4CYV8 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..d37bde2437782f22d7ec7e2315c98bc90c7efa42 GIT binary patch literal 6148 zcmeHKPixdb6rX8Vo2eoZJgnG5z=Ixo*rIhQy~H&w2!djYJ@{u$nxPv=GfR@)JuC~s z58wyTtF7Oo`Vl;M@>_V;_hw$9B`bOovGd@~?`7uq-t7FA%w!m2yf;eL7;_n84me_K z8JanUs2Wk>lQ8g-iQPFo-!ZeX_ zRP3fnHQ15)Rwl7@{Up&5KJ7!&r&(*yVoA5yo%CX7P_9P@nSd46E*3n zQJ$2VPsMfoB&r5bN8I$KuNNR3(RbU^>3Vm4)w|o>n5}x#Znp#RoqMyH5YF{m+fQGO z-n@PH{=?zX$Ky{ri*eZGv|S}UfzJ>$M9lWr!aa2`G^86}=5Y>G5Rh=rw{|ezUOB!$ zpO^d*Z#XzTr;k%Ne%ClG@=WFXFm|#Y{TG^w1f7~G^ozehZuur_GY8K=t!rU)~bxNp$5RspNPSp^o&ql@SN*01mXXOrxcRlq9nUn#&_K^XL4Np!Y07Kdl8 t2mTry4SBUeodOLV$2!2HxDBoi#ykuFeZtxx^nlq90WE`VtO9>kfuGRhk1zlL literal 0 HcmV?d00001 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; + } + } + + }