|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 第十七章Web程式語言和資料庫應用 目的
範例說明
ASP
PHP
JSP
PERL
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 目的 介紹四個常用的Web程式語言和其資料庫介面:
ASP
微軟所推出,是目前在Windows平台上被廣泛使用的一種Web程式語言
PHP
開放原始碼的Web程式語言,廣泛使用在Linux平台
JSP
類似Java之Web程式語言,普遍使用在Java平台上
PERL
最早被使用的Web程式語言
但撰寫方式類似於一般程式語言,而非如前三種的描述性語言
重點為Web程式如何與資料庫連線並存取資料
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 目的(Cont.) 描述性語言 (PHP)
Example
PERL
#!/user/local/bin/perl
&html_header(-title=>″Example″);
print "Hi, I'm a PERL program!";
&html_footer;
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 範例 網路書店線上購物系統的產品(Product)資料表之新增,刪除,修改,和查詢
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 範例(Cont.) 新增商品 完成新增一筆 回查詢畫面
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 範例(Cont.) 新增(Cont.)
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 範例(Cont.) 刪除該筆記錄
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 範例(Cont.) 修改商品資訊 修改該筆記錄
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 範例(Cont.) 完成修改
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* 範例(綱目)
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* ASP 全名為Active Server Pages(動態網頁伺服器)
優點:
嵌在HTML裡,與HTML或Script語言結合,不需要手動編譯或是連接程式
具有物件觀念( Object based )。
存取資料庫相當簡便
隱藏程式碼,客戶端僅看到由ASP輸出的動態HTML文件
編寫容易,縮短網路程式開發時間
系統安裝
Windows環境下安裝IIS網站伺服器
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* ASP(Cont.) 程式範例
本範例是用ASP存取MySql 資料庫 “bookstore”
資料庫連結透過ODBC,因此需要安裝myodbc ,再設定odbc的資料來源
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* ASP查詢(Lisp.asp) 1.
2.
3. | @購物網-管理介面 |
4.
5.
6. | 商品編號 |
7. …
11. 修改 |
12.
13.<%
14. '建立資料庫連結物件
15. set conn = Server.CreateObject("ADODB.Connection")
16. '開啟資料庫連結
17. conn.Open "test"
18. '用Big5編碼
19. Set rs = conn.Execute("set names big5")
20. query = "SELECT * FROM Product"
21. Set rs = conn.Execute(query)
23. while not rs.EOF
24.%>
25.
26. | <%=rs("pNo")%> |
27. …
32.
33.<%
34. rs.MoveNext
35. wend
36.%>
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* ASP新增(Insert.asp)
1.<%
2. pNo=request("pNo")
3. pName=request("pName")
4. unitPrice=request("unitPrice")
5. category=request("category")
6. submit=request("submit")
7.
8.if submit="新增" then
9. '建立資料庫連結物件
10. set conn = Server.CreateObject("ADODB.Connection")
11. '開啟資料庫連結
12. conn.Open "test"
13.
14. '用Big5編碼
15. Set rs = conn.Execute("set names big5")
16. query="INSERT INTO product (pNo, pName, unitPrice, category) VALUES ('"&pNo&"', '"&pName&"', '"&unitPrice&"', '"&category&"')"
17. Set rs = conn.Execute(query)
18.
19.end if
20.%>
…
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* ASP修改(Update.asp) 8. …
9.if submit="修改" then
10. '建立資料庫連結物件
11. set conn = Server.CreateObject("ADODB.Connection")
12. '開啟資料庫連結
13. conn.Open "test"
14.
15. '用Big5編碼
16. Set rs = conn.Execute("set names big5")
17. query="update Product set pNo='"&pNo&"', pName='"&pName&"', unitPrice='"&unitPrice&"', category='"&category&"' where pNo='"&old_pNo&"'"
18. Set rs = conn.Execute(query)
19.
20.end if
21.%>
22.
23.
24. | @購物網-管理介面 |
25.
26.
27. |
28.<%
29. if submit="修改" then
30. if rs is nothing then
31. response.Write " 修改失敗 "
32. else
33. response.Write " 已經修改成功 "
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* ASP刪除(Delete.asp) 1.<%
2. pNo=request("pNo")
3.
4. '建立資料庫連結物件
5. set conn = Server.CreateObject("ADODB.Connection")
6. '開啟資料庫連結
7. conn.Open "test"
8. query="delete FROM product where pNo='"&pNo&"'"
9. Set rs = conn.Execute(query)
10.%>
11.
12.
13. |
14. <% if rs is nothing then
15. response.Write " 刪除失敗 "
16. else
17. response.Write " 已經刪除成功 "
18. end if
19. %> |
20.
21.
22. | 查詢 |
23.
24.
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* PHP PHP在1994年推出,全名為Hypertext Preprocessor
PHP可以安裝在許多平台
Linux、HP-UX、Solaris、OpenBSD、FreeBSD、Microsoft Windows、Mac OS X等。
PHP也支援大多數的網站伺服器
Apache, Microsoft IIS, PWS, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd等
系統安裝
安裝PHP套件
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* PHP查詢(List.php) 1
9 |
10 | echo $row["pNo"];?> |
11 echo $row["pName"];?> |
12 echo $row["unitPrice"];?> |
13 echo $row["category"];?> |
14 ">刪除
15 |
16 ">修改
17 |
18
19
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* PHP新增(Insert.php) 1
|
|
|
|
|
黃三益2008 資料庫的核心理論與實務第四版 17-* PHP修改(Update.php) 1
|
|
|
|
|
|
|
|
|
|
Copy the following code to your webpage or blog to embed this presentation:
<a href="http://www.slidefinder.net/c/ch17/33006246" class="slidefinder">Ch17</a>
<script type="text/javascript" src="http://www.slidefinder.net/scripts/embedded.js"></script>
<a href="http://www.slidefinder.net/c/ch17/33006246" class="slidefinder">Ch17</a>
Det3
<script type="text/javascript" src="http://www.slidefinder.net/scripts/embedded.js"></script>
Share this presentation:
Sitemap
| |
Comments