Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝...

82
Chen-Ching Ting () Mechanical Engineering, National Taipei University of Technology (台北) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group April 28, 2010 Chen-Ching Ting () Mechanical Engineering, National Taipei University of Technology (http April 28, 2010 1 / 82

Transcript of Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝...

Page 1: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理與資料庫應用

Chen-Ching Ting(丁振卿)

Mechanical Engineering, National Taipei University of Technology(國立台北科技大學機械系)

Homepage: http://cct.me.ntut.edu.tw/E-mail: [email protected]

CCT Group

April 28, 2010

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 1 / 82

Page 2: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

課程大綱 I

1 MySQL資料庫伺服器安裝

2 資料庫建立資料庫伺服器連結資料庫建立與刪除表格建立與刪除表格欄位建立與刪除表格內容輸入、讀取、刪除與更新資料庫表格內容搜尋

3 管理程式編寫流程分析設定題目資料庫及表格分析與製作表格內容存取PHP/HTML檔案編寫終端使用者工作畫面整合

4 範例資料庫與表格製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 2 / 82

Page 3: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

課程大綱 II

留言板製作功課表製作實驗條件製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 3 / 82

Page 4: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

參考文獻

施威銘研究室,最新C 程式語言,旗標出版股份有限公司,ISBN=957-717-964-9,2005。

M. Zandstra, Teach Yourself PHP4 in 24 Hours, SAMS, 2000.

W.J. Gilmore, A Programmer’s Introduction to PHP 4.0, Apress, ‘ISBN(pbk):1-893115-85-2, 2001.

洪資勝,CCT Group Presentation 報告,光頻科技有限公司負責人,2006.

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 4 / 82

Page 5: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

MySQL資資資料料料庫庫庫伺伺伺服服服器器器安安安裝裝裝

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 5 / 82

Page 6: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

MySQL資料庫伺服器安裝

1 Windows XP作業系統下之MySQL資料庫伺服器安裝

2 Ubuntu Linux作業系統下之MySQL資料庫伺服器安裝

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 6 / 82

Page 7: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

Windows XP作作作業業業系系系統統統下下下之之之MySQL資資資料料料庫庫庫伺伺伺服服服器器器安安安裝裝裝

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 7 / 82

Page 8: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

Windows XP作業系統下之MySQL資料庫伺服器安裝

1 To install the MySQL Server to

d:\www\mysql

or where you like.

2 To start the file

d:\www\mysql\bin\winmysqladmin.exe

and give a login name and password for Root.

3 To open the file

c:\windows\my.ini

and change the datadir from

d:/www/mysql/data

to where you like. e.g.

d:/user/www/mysql/data

4 To use batch file for opening the MySQL server:

net start mysql

To use batch file for closing the MySQL server:

net stop mysql

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 8 / 82

Page 9: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

Ubuntu Linux作作作業業業系系系統統統下下下之之之MySQL資資資料料料庫庫庫伺伺伺服服服器器器安安安裝裝裝

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 9 / 82

Page 10: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

必要安裝的程式

1 apache2:

2 libapache2-mod-php5

3 php5:

4 php5-gd:

5 php5-mysql:

6 mysql-server-5:

7 mysql-query-browser:

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 10 / 82

Page 11: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

進行MySQL Database Server設定

MySQL Database Server的my.conf檔案在

/etc/mysql/

下,datadir資料在

/var/lib/mysql

change the datadir from /var/lib/mysql to where you like. e.g./home/www/mysql/data 下,將/var/lib/mysql下資料複製到/home/www/mysql/data 下並使用

"mysqladmin -u root password cct"

設定root的密碼,可打開系統/管理/服務,並選擇MySQL,或者使用

"sudo /etc/init.d/mysql start" 啟動"sudo /etc/init.d/mysql stop" 停止

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 11 / 82

Page 12: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

MySQL資料庫伺服器安裝

設定新user

shell>mysql {user=root mysqlmysql> GRANT ALL PRIVILEGES ON *.* TO ’username’@’localhost’

-> IDENTIFIED BY ’password’ WITH GRANT OPTION;

啟動mysql-query-browser登入mysql database的user進行root等密碼設定。

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 12 / 82

Page 13: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立

資資資料料料庫庫庫建建建立立立

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 13 / 82

Page 14: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立

資料庫建立

1 資料庫伺服器連結

2 資料庫建立與刪除

3 資料庫表格建立與刪除

4 資料庫表格內容輸入、讀取、刪除與更新

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 14 / 82

Page 15: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 資料庫伺服器連結

資資資料料料庫庫庫伺伺伺服服服器器器連連連結結結

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 15 / 82

Page 16: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 資料庫伺服器連結

資料庫伺服器連結

$link=mysql_connect("localhost", "user","password");

mysql_select_db("database",$link);

$results=mysql_query("select * from table order by date desc",$link);

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 16 / 82

Page 17: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 資料庫建立與刪除

資資資料料料庫庫庫建建建立立立與與與刪刪刪除除除

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 17 / 82

Page 18: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 資料庫建立與刪除

資料庫建立與刪除

<?php

mysql_connect("localhost", "user","password");

if($tg==’ins’)

{

mysql_query("create database $db")or die("Error: ".mysql_error());

print "Database $db 已建立成功。";

}

elseif($tg==’del’)

{

mysql_query("drop database $db")or die("Error: ".mysql_error());

print "Database $db 已刪除成功。";

}

else

print "工作未完成。";

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 18 / 82

Page 19: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格建立與刪除

表表表格格格建建建立立立與與與刪刪刪除除除

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 19 / 82

Page 20: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格建立與刪除

表格建立與刪除

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("$db",$link);

if($tg==’ins’)

{

mysql_query("CREATE TABLE $tab( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id))")

or die("Error: ".mysql_error());

print "Table $tab 已建立成功。";

}

elseif($tg==’del’)

{

mysql_query("drop table $tab")or die("Error: ".mysql_error());

print "Table $tab 已刪除成功。";

}

else

print "工作未完成。";

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 20 / 82

Page 21: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格欄位建立與刪除

表表表格格格欄欄欄位位位建建建立立立與與與刪刪刪除除除

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 21 / 82

Page 22: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格欄位建立與刪除

表格欄位建立與刪除

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("$db",$link);

if($tg==’ins’)

{

mysql_query("alter table $tab add $col $ty")or die("Error: ".mysql_error());

print "Column $col 已建立成功。";

}

elseif($tg==’del’)

{

mysql_query("alter table $tab drop $col")or die("Error: ".mysql_error());

print "Column $col 已刪除成功。";

}

else

print "工作未完成。";

}

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 22 / 82

Page 23: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格內容輸入、讀取、刪除與更新

表表表格格格內內內容容容輸輸輸入入入、、、讀讀讀取取取、、、刪刪刪除除除與與與更更更新新新

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 23 / 82

Page 24: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格內容輸入、讀取、刪除與更新

表格內容輸入

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("database",$link);

$ergebnis=mysql_query("select max(id) as maxid from table");

$data=mysql_fetch_array($results);

$data[id]=$data[maxid]+1;

echo "<form action=projectin.php method=get target=projectshow>";

echo "<table>";

echo "<tr><td>ID </td><td><input type=text name=id>建立時不必填寫</td></tr>";

echo "<tr><td>計劃書標題 </td><td><input type=text name=ti size=100></td></tr>";

echo "<tr><td>申請日期 </td><td><input type=text name=da size=100></td></tr>";

echo "<tr><td>申請單位 </td><td><input type=text name=le size=100></td></tr>";

echo "<tr><td>執行期間 </td><td><input type=text name=du size=100></td></tr>";

echo "<tr><td></td><td><input type=submit value=輸入></td></tr>";

echo "</table>";

echo "</form>";

?>

projectin.php

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("database",$link);

mysql_query("insert into project values(’’,’$ti’,’$da’,’$le’,’$du’)")or die("Error:".mysql_error());

print "資料建立成功。";

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 24 / 82

Page 25: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格內容輸入、讀取、刪除與更新

表格內容讀取

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("database",$link);

$results=mysql_query("select * from table order by date DESC",$link);

echo "<table border=3>";

echo "<tr><td>ID</td><td>計劃書標題</td><td>申請日期</td><td>申請單位</td><td>執行期間</td></tr>";

while ($data=mysql_fetch_array($results))

{

printf("<tr><td><form action=projectshow.php method=get>

<input type=hidden name=id value=$data[id]>

<input type=submit value=$data[id]></form></td><td>$data[title]</td>

<td>$data[date]</td><td>$data[lead]</td><td>$data[duration]</td></tr>");}

echo "</table>";

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 25 / 82

Page 26: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格內容輸入、讀取、刪除與更新

表格內容刪除

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("database",$link);

mysql_query("delete from table where id=’$id’")or die("Error: ".mysql_error());

print "資料刪除成功。";

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 26 / 82

Page 27: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 表格內容輸入、讀取、刪除與更新

表格內容更新

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("database",$link);

mysql_query("update table set

title=’$ti’,

date=’$da’,

lead=’$le’,

duration=’$du’ where id=’$id’")or die("Error: ".mysql_error());

print "資料更新成功。";

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 27 / 82

Page 28: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 資料庫表格內容搜尋

資資資料料料庫庫庫表表表格格格內內內容容容搜搜搜尋尋尋

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 28 / 82

Page 29: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

資料庫建立 資料庫表格內容搜尋

資料庫表格內容搜尋

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("database",$link);

$results=mysql_query("select * from table order by date DESC",$link);

echo "<table border=3>";

echo "<tr><td>ID</td><td>計劃書標題</td><td>申請日期</td><td>申請單位</td><td>執行期間</td></tr>";

while ($data=mysql_fetch_array($results))

{

if($ky==’全部’)

{

printf("<tr><td><form action=projectshow.php method=get>

<input type=hidden name=id value=$data[id]>

<input type=submit value=$data[id]></form></td><td>$data[title]</td>

<td>$data[date]</td><td>$data[lead]</td><td>$data[duration]</td></tr>");

}

elseif($data[name]==$ky)

{

printf("<tr><td><form action=projectshow.php method=get>

<input type=hidden name=id value=$data[id]>

<input type=submit value=$data[id]></form></td><td>$data[title]</td>

<td>$data[date]</td><td>$data[lead]</td><td>$data[duration]</td></tr>");

}

}

echo "</table>";

?>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 29 / 82

Page 30: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析

管管管理理理程程程式式式編編編寫寫寫流流流程程程分分分析析析

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 30 / 82

Page 31: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析

管理程式編寫流程分析

設定題目

⇓資料庫及表格分析與製作

⇓表格內容存取PHP/HTML檔案編寫

⇓終端使用者工作畫面整合

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 31 / 82

Page 32: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 設定題目

設設設定定定題題題目目目

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 32 / 82

Page 33: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 設定題目

設定題目

依公司經營型態和各組織部門之特性而異,需求各有不同。目前以光頻公司業務部所需要之資料庫為例,共四種表格:

1 客戶基本資料表

2 聯絡人資料表

3 交易記錄表

4 往來記錄表

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 33 / 82

Page 34: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 設定題目

客戶基本資料表

客戶資料檔:名稱、地址、事業類別、產品、電話、傳真、E-Mail、聯絡人、交易記錄。

資料庫表格:

名稱 地址 事業類別 產品 電話 傳真 E-Mail 聯絡人 交易記錄

終端使用者畫面:

客戶基本資料表

名稱 地址 事業類別 產品 電話 傳真 E-Mail 聯絡人 交易記錄

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 34 / 82

Page 35: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 設定題目

聯絡人資料表

聯絡人資料表:姓名、暱稱、生日、就職單位、職位、手機號、E-Mail。資料庫表格:

姓名 暱稱 就職單位 職位 手機號 E-Mail

終端使用者畫面:

聯絡人資料表

姓名

暱稱

就職單位

職位

手機號

E-Mail

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 35 / 82

Page 36: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 設定題目

交易記錄表

交易記錄表:每次交易金額、日期、品名、數量。

資料庫表格:

每次交易金額 日期 品名 數量

終端使用者畫面:

交易記錄表

每次交易金額 日期 品名 數量

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 36 / 82

Page 37: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 設定題目

往來記錄表

來往記錄表:客戶、拜訪或通聯日期、洽談內容。

資料庫表格:

客戶 拜訪或通聯日期 洽談內容

XXX

終端使用者畫面:

客戶:XXX

拜訪或通聯日期 洽談內容

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 37 / 82

Page 38: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 資料庫及表格分析與製作

資資資料料料庫庫庫及及及表表表格格格分分分析析析與與與製製製作作作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 38 / 82

Page 39: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 資料庫及表格分析與製作

資料庫及表格分析與製作

資料庫的概念即如倉庫,一個資料庫即代表一個倉庫,在倉庫中所架設的架子,在資料庫中即代表表格,MySQL之資料庫即是一個資料夾,每一個表格由三個檔案來記錄。資料庫1:

表格1 表格2 表格3

表格4 表格5 表格6

資料庫2:

表格1 表格2 表格3

表格4 表格5 表格6

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 39 / 82

Page 40: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 表格內容存取PHP/HTML檔案編寫

表表表格格格內內內容容容存存存取取取PHP/HTML檔檔檔案案案編編編寫寫寫

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 40 / 82

Page 41: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 表格內容存取PHP/HTML檔案編寫

表格內容存取PHP/HTML檔案編寫

管理者:

1 儲存--4 files

2 讀取--4 files

3 修改--4 files

4 刪除--4 files

使用者:

1 讀取--4 files

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 41 / 82

Page 42: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 終端使用者工作畫面整合

終終終端端端使使使用用用者者者工工工作作作畫畫畫面面面整整整合合合

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 42 / 82

Page 43: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

管理程式編寫流程分析 終端使用者工作畫面整合

終端使用者工作畫面整合

將所編好的程式進行單一畫面整合以方便使用者工作。

業務部 工程部 財會部

客戶基本資料 歡迎使用業務部資料庫!!

新增

查看

客戶交易紀錄

新增

查看

客戶來往紀錄

新增

查看

終端使用者

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 43 / 82

Page 44: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例

範範範例例例

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 44 / 82

Page 45: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例

範例

1 資料庫與表格製作

2 留言板製作

3 功課表製作

4 實驗條件製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 45 / 82

Page 46: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

資資資料料料庫庫庫與與與表表表格格格製製製作作作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 46 / 82

Page 47: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

資料庫與表格製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 47 / 82

Page 48: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

資料庫與表格製作–createindex.html

<html><head><title>表格製作</title></head><frameset framespacing="0" frameborder="0" rows="10%,*"><frame src=create.htm scrolling=no><frame src=welcome.htm name=create scrolling=auto></frameset><noframes><body>Your browse can not view frames!!</body></noframes></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 48 / 82

Page 49: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

資料庫與表格製作–create.html

<html><style><!--a {text-decoration:none}--></style><head><title>表格製作</title></head><body bgcolor="#c0c0c0"><table><tr><td width=200><a href=./database.htm target=create>建立/刪除 database</a></td><td width=200><a href=./table.htm target=create>建立/刪除 table</a></td><td width=300><a href=./tablecol.htm target=create>加入/刪除在 table 中的 column </a></td></tr></table></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 49 / 82

Page 50: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

資料庫製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 50 / 82

Page 51: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

資料庫與表格製作–database.html

<html><head><title>database</title></head><body bgcolor=#c0c0c0><font color=blue size=4><b>建立/刪除在 MySQL 的 Database﹕</font><form action=datain.php method=get target=welcome><select name=tg><option value=ins>建立</option><option value=del>刪除</option></select><hr>請輸入在 MySQL 的 Database 名稱﹕<br><input type=text name=db><input type=submit value=輸入></form><iframe src=welcome.htm name=welcome></iframe></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 51 / 82

Page 52: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

表格製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 52 / 82

Page 53: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

表格製作–table.html

<html><head><title>table</title></head><body bgcolor=#c0c0c0><font color=blue size=4><b>建立/刪除在 MySQL 的 table</b></font><form action=tabin.php method=get target=welcome>首先輸入一 Database 名稱﹕<br><input type=text name=db><br><hr>建立/刪除在 MySQL 的 table ﹕<br><select name=tg><option value=ins>建立</option><option value=del>刪除</option></select><hr>請輸入在 MySQL 的 Table 名稱﹕<br><input type=text name=tab><input type=submit value=輸入></form><iframe src=welcome.htm name=welcome></iframe></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 53 / 82

Page 54: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

表格欄位資料型態製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 54 / 82

Page 55: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

表格欄位資料型態製作–tablecol.html

<html><head><title>table</title></head><body bgcolor=#c0c0c0><font color=blue size=4><b>加入/刪除在 table 中的 column</b></font><form action=tabincol.php method=get target=welcome>首先輸入一 Database 名稱﹕<input type=text name=db><hr>選擇加入/刪除在 MySQL 的 table 中的 Column﹕<select name=tg><option value=ins>建立</option><option value=del>刪除</option></select><hr>請輸入在 MySQL 的 Table 名稱﹕<input type=text name=tab><hr>請輸入要加入/刪除的名稱與類型﹕<br>名稱﹕<input type=text name=col><br>類型﹕<select name=typ><option value=tinytext>tinytext</option><option value=text>text</option><option value=mediumtext>mediumtext</option><option value=longtext>longtext</option><option value=char>char</option><option value=varchar>varchar</option><option value=integer>integer</option><option value=float>float</option></select><br>大小﹕<input type=text name=nu><br>(注意﹗﹗varchar 大小填 0-255﹐類型 text 時不填大小﹐float 時大小填如 4,2 )<br><input type=submit value=輸入></form><iframe src=welcome.htm name=welcome></iframe></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 55 / 82

Page 56: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

資料庫建立與刪除–datain.php

<html><head><title>database</title></head><body bgcolor=#c0c0c0><?phpmysql_connect("localhost", "user","password");if($tg==’ins’){

mysql_query("create database $db")or die("Error: ".mysql_error());print "Database $db 已建立成功。";

}elseif($tg==’del’){

mysql_query("drop database $db")or die("Error: ".mysql_error());print "Database $db 已刪除成功。";

}else

print "工作未完成。";?></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 56 / 82

Page 57: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

表格建立與刪除–tabin.php

<html><head><title>table</title></head><body bgcolor=#c0c0c0><?php$link=mysql_connect("localhost", "user","password");mysql_select_db("$db",$link);if($tg==’ins’){

mysql_query("CREATE TABLE $tab( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id))")or die("Error: ".mysql_error());print "Table $tab 已建立成功。";

}elseif($tg==’del’){

mysql_query("drop table $tab")or die("Error: ".mysql_error());print "Table $tab 已刪除成功。";

}else

print "工作未完成。";?></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 57 / 82

Page 58: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 資料庫與表格製作

表格欄位建立與刪除–tabincol.php

<html><head><title>table</title></head><body bgcolor=#c0c0c0><?php$link=mysql_connect("localhost", "user","password");mysql_select_db("$db",$link);$ty="$typ($nu)";if($nu!=NULL){

if($tg==’ins’){

mysql_query("alter table $tab add $col $ty")or die("Error: ".mysql_error());print "Column $col 已建立成功。";

}elseif($tg==’del’){

mysql_query("alter table $tab drop $col")or die("Error: ".mysql_error());print "Column $col 已刪除成功。";

}else

print "工作未完成。";}else{

if($tg==’ins’){

mysql_query("alter table $tab add $col $typ")or die("Error: ".mysql_error());print "Column $col 已建立成功。";

}elseif($tg==’del’){

mysql_query("alter table $tab drop $col")or die("Error: ".mysql_error());print "Column $col 已刪除成功。";

}else

print "工作未完成。";}

?></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 58 / 82

Page 59: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 留言板製作

留留留言言言板板板製製製作作作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 59 / 82

Page 60: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 留言板製作

留言板輸入

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 60 / 82

Page 61: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 留言板製作

留言板輸入–letter.html

<html>

<style><!--a {text-decoration:none}--></style>

<HEAD>

<TITLE>留言板</TITLE>

</HEAD>

<style type="text/css">

body {background-image:url(/fig/lucky.gif); background-attachment:fixed; }

</style>

<BODY bgcolor="Silver">

<font color=green size="6"><b>留言板:</b></font>

<form action=./letter.php method=get>

<table>

<tr><td>留言者<input type=text name=fna></td></tr>

<tr><td>主題<input type=text name=tna></td></tr>

<tr><td>內容:</td></tr>

<tr><td><textarea name=in rows=14 cols=80></textarea></td></tr>

<tr><td><input type=submit value=送出留言></td></tr>

</table>

</form>

</BODY>

</html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 61 / 82

Page 62: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 留言板製作

留言板輸入–letter.php

<html>

<style><!--a {text-decoration:none}--></style>

<HEAD>

<TITLE>Letter</TITLE>

</HEAD>

<style type="text/css">

body {background-image:url(/fig/lucky.gif); background-attachment:fixed; }

</style>

<BODY bgcolor="Silver">

<?php

$theDate = time();

$da=date(’Y-m-d’,$theDate);

$ti=date(’H:i:s’,$theDate);

$link=mysql_connect("localhost", "user","password");

mysql_select_db("cctlab",$link);

mysql_query("insert into newsgroup values(’’,’$fna’,’$tna’,’$da’,’$ti’,’$in’)")or die("Error: ".mysql_error());

print "謝謝﹐已成功留言。";

?>

</BODY>

</html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 62 / 82

Page 63: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功功功課課課表表表製製製作作作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 63 / 82

Page 64: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 64 / 82

Page 65: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入–course.php I

<html>

<style><!--a {text-decoration:none}--></style>

<head>

<title>course</title>

</head>

<body bgcolor=#c0c0c0>

<?php

$number[]="1";

$number[]="2";

$number[]="3";

$number[]="4";

$number[]="中午";

$number[]="5";

$number[]="6";

$number[]="7";

$number[]="8";

$number[]="9";

$number[]="A";

$number[]="B";

$number[]="C";

$number[]="D";

$time[]="08:10~09:00";

$time[]="09:10~10:00";

$time[]="10:10~11:00";

$time[]="11:10~12:00";

$time[]="12:10~13:00";

$time[]="13:10~14:00";

$time[]="14:10~15:00";

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 65 / 82

Page 66: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入–course.php II

$time[]="15:10~16:00";

$time[]="16:10~17:00";

$time[]="17:10~18:00";

$time[]="18:30~19:20";

$time[]="19:20~20:10";

$time[]="20:20~21:10";

$time[]="21:10~22:00";

$link=mysql_connect("localhost", "user","password");

mysql_select_db("cctlab",$link);

$ergebnis=mysql_query("select max(id) as maxid from course");

$datensatz=mysql_fetch_array($ergebnis);

$datensatz[id]=$datensatz[maxid]+1;

echo "<table>";

echo "<tr><td width=350>輸入在 MySQL 的 <font color=red>course</font> 表格資料﹕</td>";

echo "<td><form action=courseshow.php method=get>";

echo "ID=<input type=text name=id value=\"$datensatz[id]\" size=6>";

echo "<input type=submit value=查看結果></form></td></tr>";

echo "</table>";

echo "<form action=coursein.php method=get target=courseshow>";

echo "<table frame=border>";

echo "<tr><td colspan=2>姓名:<input type=text size=10 name=na></td><td colspan=2>

學年度:<input type=text size=10 name=se></td><td colspan=5>ID:<input type=text name=id size=4>建立時不必填寫</td></tr>\n";

echo "<tr><td>節次</td><td>時間\星期</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td><td>日</td></tr>";

for($i=1;$i<=14;$i++)

{

$num=$i-1;

printf("<tr><td>$number[$num]</td><td>$time[$num]</td>");

for($j=1;$j<=7;$j++)

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 66 / 82

Page 67: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入–course.php III

{

printf("<td><input type=text size=20 name=co$i$j></td>");

}

printf("</tr>\n");

}

echo "<tr><td colspan=9><input type=submit value=輸入></td></tr>\n";

echo "</table>\n";

echo "</form>\n";

?>

<iframe src=./welcome.htm name=courseshow width=800 height=600>

Your browser can not read frames.

</iframe>

</body>

</html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 67 / 82

Page 68: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入–coursein.php I

<html>

<head>

<title>coursein</title>

</head>

<body bgcolor=#c0c0c0>

<?php

$link=mysql_connect("localhost", "user","password");

mysql_select_db("cctlab",$link);

$ergebnis=mysql_query("select * from course",$link);

mysql_query("insert into course values(’’,’$na’,’$se’,’$co11’

,’$co12’

,’$co13’

,’$co14’

,’$co15’

,’$co16’

,’$co17’

,’$co21’

,’$co22’

,’$co23’

,’$co24’

,’$co25’

,’$co26’

,’$co27’

,’$co31’

,’$co32’

,’$co33’

,’$co34’

,’$co35’

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 68 / 82

Page 69: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入–coursein.php II

,’$co36’

,’$co37’

,’$co41’

,’$co42’

,’$co43’

,’$co44’

,’$co45’

,’$co46’

,’$co47’

,’$co51’

,’$co52’

,’$co53’

,’$co54’

,’$co55’

,’$co56’

,’$co57’

,’$co61’

,’$co62’

,’$co63’

,’$co64’

,’$co65’

,’$co66’

,’$co67’

,’$co71’

,’$co72’

,’$co73’

,’$co74’

,’$co75’

,’$co76’

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 69 / 82

Page 70: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入–coursein.php III

,’$co77’

,’$co81’

,’$co82’

,’$co83’

,’$co84’

,’$co85’

,’$co86’

,’$co87’

,’$co91’

,’$co92’

,’$co93’

,’$co94’

,’$co95’

,’$co96’

,’$co97’

,’$co101’

,’$co102’

,’$co103’

,’$co104’

,’$co105’

,’$co106’

,’$co107’

,’$co111’

,’$co112’

,’$co113’

,’$co114’

,’$co115’

,’$co116’

,’$co117’

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 70 / 82

Page 71: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表輸入–coursein.php IV

,’$co121’

,’$co122’

,’$co123’

,’$co124’

,’$co125’

,’$co126’

,’$co127’

,’$co131’

,’$co132’

,’$co133’

,’$co134’

,’$co135’

,’$co136’

,’$co137’

,’$co141’

,’$co142’

,’$co143’

,’$co144’

,’$co145’

,’$co146’

,’$co147’

)")or die("Error: ".mysql_error());

print "資料建立成功。";

?>

<body>

</html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 71 / 82

Page 72: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表查看

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 72 / 82

Page 73: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表查看

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 73 / 82

Page 74: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表查看

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 74 / 82

Page 75: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

功課表查看–courseindex.html

<html><head><title>查看課表</title></head><frameset framespacing="0" frameborder="0" rows="12%,*"><frame src=courseselect.htm scrolling=no><frame src=welcome.htm name=welcome scrolling=auto></frameset></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 75 / 82

Page 76: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

學期選擇–courseselect.html

<html><style><!--a {text-decoration:none}--></style><head><title>查看課表</title></head><body bgcolor=#c0c0c0><table><tr><td><iframe src=semesterselect.php width=200 height=60 scrolling=no name=semesterselect></iframe></td><td><iframe src=cctgroupselect.htm width=400 height=60 scrolling=no name=cctgroupselect></iframe></td></tr></table></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 76 / 82

Page 77: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

學期選擇–semesterselect.php

<html><style><!--a {text-decoration:none}--></style><head><title>查看學期</title></head><body bgcolor=#c0c0c0><?php$link=mysql_connect("localhost", "user","password");mysql_select_db("cctlab",$link);$ergebnis=mysql_query("select * from auswahl",$link);printf("<form action=cctgroupselect.php method=get target=cctgroupselect>");printf("<select name=se>");while ($datensatz=mysql_fetch_array($ergebnis)){

printf("<option>$datensatz[semester]</option>");}printf("</select>");printf("<input type=submit value=選擇學期>");printf("</form>");?></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 77 / 82

Page 78: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 功課表製作

學期選擇–cctgroupselect.php

<html><style><!--a {text-decoration:none}--></style><head><title>查看CCT團隊</title></head><body bgcolor=#c0c0c0><?php$link=mysql_connect("localhost", "user","password");mysql_select_db("cctlab",$link);$ergebnis=mysql_query("select * from auswahl",$link);printf("<form action=courseview.php method=get target=welcome>");printf("<select name=na>");while ($datensatz=mysql_fetch_array($ergebnis)){

printf("<option>$datensatz[name]</option>");}printf("</select>");printf("<input type=hidden name=ky value=\"$se\">");printf("<input type=submit value=CCT團隊>");printf("</form>");?></body></html>

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 78 / 82

Page 79: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 實驗條件製作

實實實驗驗驗條條條件件件製製製作作作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 79 / 82

Page 80: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 實驗條件製作

實驗條件製作

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 80 / 82

Page 81: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 實驗條件製作

結結結論論論

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 81 / 82

Page 82: Chen-Ching Ting 丁振卿 Mechanical Engineering, National ... · MySQL資料庫伺服器安裝 Windows XP作業系統下之MySQL資料庫伺服器安裝 1 To install the MySQL Server

範例 實驗條件製作

結論

資料庫的學習與應用除了對工作的實際幫助外,更是自己訓練組織能力與邏輯推理能力非常好的工具,特別是在實驗室中對實驗數據的管理,乃非常實用,對於每個工程師而言,資料庫的應用能力更應視為必備的能力。

Chen-Ching Ting (丁振卿) Mechanical Engineering, National Taipei University of Technology (國立台北科技大學機械系) Homepage: http://cct.me.ntut.edu.tw/ E-mail: [email protected] CCT Group ()管理與資料庫應用 April 28, 2010 82 / 82