IDC簡介 |
Internet數據庫連接器(IDC,Internet Database Connector)技術最早出現於Microsoft Internet Information Server 2.0版本中,Web客戶通過IDC訪問Web服務器上的數據。IDC使用戶通過瀏覽器可以瀏覽服務器上的信息和訪問後臺數據庫。IDC是ISAPI的一個具體實現,利用IDC生成一個從客戶端HTML頁面到服務器端IIS的數據庫操作。它是一個HTTPODBC.DLL(動態連接庫)。
與傳統的CGI技術相比,IDC在一定程度上解決了CGI腳本較慢的訪問速度和使用維護復雜的問題。在CGI技術中,客戶提出請求,服務器把請求寫入初始化文件,進程從初始化文件中讀取查詢並對後臺數據庫執行查詢。進程將後臺數據庫返回數據形式化為HTML字符串,並傳送給服務器。服務器再把HTML串傳送給客戶。可以看出,這樣的流程是復雜緩慢的。特別在網絡擁塞時,CGI的速度會另人難以忍受。
IDC工作需求
IDC工作原理
以下為一個典型的工作流程。客戶端通過瀏覽器向服務器發出請求,同時通過HTTP請求一個IDC文件。服務器接收請求,並調用HTTPODBC.DLL接收該請求的所有參數。HTTPODBC.DLL用IDC文件中的SQL語句對數據源進行各種數據操作,再將結果通過IDC文件中指定的HTX文件傳回給客戶端。
IDC執行實例
1 建立後臺數據庫
2.出現內容為“The database device was successfully created.”的提示框。單擊確定。在Database Devices下多了一個新建的設備stu95。
3.出現Manage Tables框。輸入所需的字段。如:
4.單擊保存圖標,出現Specify Table Name框,在New Table Name欄中輸入表名,如people。單擊OK。
3 編寫HTML文件
class.htm文件:
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <meta name="Microsoft Theme" content="none"> <meta name="Microsoft Border" content="none"> <title>同學通訊錄</title> </head> <body bgcolor="#FFFFFF"> <p><big>同學通訊錄:</big></p> <p> </p> <p><big><big> <a href="search.htm">查詢</a></big></big></p> <p><big><big> <a href="http://misserver/add.htm">添加</a></big></big></p> </body> </html> add.htm源文件 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <meta name="Microsoft Border" content="none"> <title>添加記錄</title> </head> <body> <p> </p> <p>請在下表中填寫相關的信息:</p> <form method="POST" action="scripts/class/add.idc"> <table border="1" cellpadding="0" width="100%"> <tr> <td width="50%"><div align="right"><p>姓名:</td> <td width="50%"><input type="text" name="txtname" size="20"></td> </tr> <tr> <td width="50%"><div align="right"><p>年齡:</td> <td width="50%"><input type="text" name="txtage" size="2"></td> </tr> <tr> <td width="50%"><div align="right"><p>性別:</td> <td width="50%"><input type="radio" value="男" checked name="gender">男<input type="radio" name="gender" value="女">女</td> </tr> <tr> <td width="50%"><div align="right"><p>電話:</td> <td width="50%"><input type="text" name="txtphone" size="20"></td> </tr> <tr> <td width="50%"><div align="right"><p>Email:</td> <td width="50%"><input type="text" name="txtemail" size="20"></td> </tr> <tr> <td width="50%"><div align="right"><p><input type="submit" value="添加" name="cmdadd"></td> <td width="50%"><input type="reset" value="清除" name="cmdclear"></td> </tr> </table> </form> <p><a href="class.htm">返回</a></p> </body> </html>
search.htm文件
<html>
<head> <title>同學通訊錄</title> </head> <body bgcolor="#FFFFFF"> <form method="POST" action="/scripts/class/search.idc"> <p>輸入您想查詢的同學姓名:</p> <p><input type="text" name="txtname" size="20"><input type="submit" value="開始" name="B1"><input type="reset" value="清除" name="B2"></p> </form> <p><a href="class.htm">返回</a></p> </body> </html>
4 編寫IDC文件
Datasource:class
Username:sa Password: Template:add.htx SQLStatement: +INSERT INTO people(NAME,AGE, SEX, PHONE, email) +VALUES('%txtname%',convert(int,'%txtage%'),'%gender%', +'%txtphone%','%txtemail%')
edit.idc|文件:
Datasource:class
Username:sa Password: Template:edit.htx SQLStatement: +UPDATE people +SET NAME='%txtname%',AGE=convert(int,'%txtage%'), +SEX='%gender%', +PHONE='%txtphone%', email='%txtemail%' +WHERE (name='%hidname%') +AND(age=convert(int,'%hidage%')) +AND(sex='%hidgender%') +AND(phone='%hidphone%') +AND(email='%hidemail%')
delete.idc文件:
Datasource:class
Username:sa Password: Template:delete.htx SQLStatement: +DELETE FROM people +WHERE (name='%hidname%') +AND(age=convert(int,'%hidage%')) +AND(sex='%hidgender%') +AND(phone='%hidphone%') +AND(email='%hidemail%')
search.idc文件:
Datasource:class
Username:sa Password: Template:search.htx SQLStatement: +SELECT NAME,AGE, SEX, PHONE, email +from stu.DBO.people +where name='%txtname%'
5 編寫HTX文件
add.htx文件:
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <meta name="Microsoft Border" content="none"> <title>添加結果</title> </head> <body> <p> </p> <p>下面的信息是您剛添加到庫中的:</p> <p> </p> <form method="POST" action="edit.idc"> <input type="hidden" name="hidage" value="<%idc.txtage%>"><input type="hidden" name="hidemail" value="<%idc.txtemail%>"><input type="hidden" name="hidgender" value="<%idc.gender%>"><input type="hidden" name="hidname" value="<%idc.txtname%>"><input type="hidden" name="hidphone" value="<%idc.txtphone%>"><table border="1" cellpadding="0" width="100%"> <tr> <td width="50%"><div align="right"><p>姓名:</td> <td width="50%"><input type="text" name="txtname" size="20" value="<%idc.txtname%>"></td> </tr> <tr> <td width="50%"><div align="right"><p>年齡:</td> <td width="50%"><input type="text" name="txtage" size="20" value="<%idc.txtage%>"></td> </tr> <tr> <td width="50%"><div align="right"><p>性別:</td> <td width="50%"><input type="text" name="gender" size="20" value="<%idc.gender%>"></td> </tr> <tr> <td width="50%"><div align="right"><p>電話:</td> <td width="50%"><input type="text" name="txtphone" size="20" value="<%idc.txtphone%>"></td> </tr> <tr> <td width="50%"><div align="right"><p>Email:</td> <td width="50%"><input type="text" name="txtemail" size="20" value="<%idc.txtemail%>"></td> </tr> <tr> <td width="100%" colspan="2">nbsp; <input type="submit" value="修改" name="cmdedit"></td> </tr> </table> </form> <form action="delete.idc" method="POST"> <input type="hidden" name="hidage" value="<%idc.txtage%>"><input type="hidden" name="hidemail" value="<%idc.txtemail%>"><input type="hidden" name="hidgender" value="<%idc.gender%>"><input type="hidden" name="hidname" value="<%idc.txtname%>"><input type="hidden" name="hidphone" value="<%idc.txtphone%>"><table width="528"> <tr> <td width="528"><div align="left"><p> <input type="submit" value="刪除" name="cmddelete"></td> </tr> </table> </form> </body> </html>
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>記錄已修改成功</title> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <meta name="Microsoft Theme" content="none"> <meta name="Microsoft Border" content="none"> </head> <body> <p>記錄已修改成功!<a href="http://misserver/class.htm">返回</a></p> </body> </html>
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>記錄已刪除成功</title> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <meta name="Microsoft Theme" content="none"> <meta name="Microsoft Border" content="none"> </head> <body> <p>記錄已刪除成功!<a href="http://misserver/class.htm">返回</a></p> <p> </p> </body> </html>
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="Microsoft Border" content="tl, default"> <title>查詢結果</title> <meta name="Microsoft Theme" content="none"> </head> <body bgcolor="#FFFFFF"> <%if idc.txtname eq ""%> <h2>通訊錄中</h2> <%else%> <h2>通訊錄中含<i> <%idc.txtname%> </i>字樣的查詢結果為</h2> <%endif%> <table border="1" cellpaddint="10"> <%begindetail%><%if CurrentRecord eq 0%> <caption>查詢結果:</caption> <tr> <td><b>姓名</b> </td> <td><b>年齡</b></td> <td><b>性別</b></td> <td><b>電話</b></td> <td><b>Email</b></td> </tr> <%endif%> <tr> <td><%name%> </td> <td align="right"><%age%> </td> <td><%sex%> </td> <td><%phone%> </td> <td><%email%> </td> </tr> <%enddetail%></table> <%if CurrentRecord eq 0%><i><b> <p></b></i><em><font color="#0000FF"><strong><big>沒有含<%idc.txtname%>的記錄,請重新檢索</big></strong><b>!</b></font> </em></p> <%endif%> <p><a href="http://misserver/search.htm">返回</a></p> </body> </html>
6 調試 class.htm文件: <html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <meta name="Microsoft Theme" content="none"> <meta name="Microsoft Border" content="none"> <title>同學通訊錄</title> </head> <body bgcolor="#FFFFFF"> <p><big>同學通訊錄:</big></p> <p> </p> <p><big><big> <a href="search.htm">查詢</a></big></big></p> <p><big><big> <a href="http://misserver/add.htm">添加</a></big></big></p> </body> </html>
add.htm源文件
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <meta name="Microsoft Border" content="none"> <title>添加記錄</title> </head> <body> <p> </p> <p>請在下表中填寫相關的信息:</p> <form method="POST" action="scripts/class/add.idc"> <table border="1" cellpadding="0" width="100%"> <tr> <td width="50%"><div align="right"><p>姓名:</td> <td width="50%"><input type="text" name="txtname" size="20"></td> </tr> <tr> <td width="50%"><div align="right"><p>年齡:</td> <td width="50%"><input type="text" name="txtage" size="2"></td> </tr> <tr> <td width="50%"><div align="right"><p>性別:</td> <td width="50%"><input type="radio" value="男" checked name="gender">男<input type="radio" name="gender" value="女">女</td> </tr> <tr> <td width="50%"><div align="right"><p>電話:</td> <td width="50%"><input type="text" name="txtphone" size="20"></td> </tr> <tr> <td width="50%"><div align="right"><p>Email:</td> <td width="50%"><input type="text" name="txtemail" size="20"></td> </tr> <tr> <td width="50%"><div align="right"><p><input type="submit" value="添加" name="cmdadd"></td> <td width="50%"><input type="reset" value="清除" name="cmdclear"></td> </tr> </table> </form> <p><a href="class.htm">返回</a></p> </body> </html>
search.htm文件
<html>
<head> <title>同學通訊錄</title> </head> <body bgcolor="#FFFFFF"> <form method="POST" action="/scripts/class/search.idc"> <p>輸入您想查詢的同學姓名:</p> <p><input type="text" name="txtname" size="20"><input type="submit" value="開始" name="B1"><input type="reset" value="清除" name="B2"></p> </form> <p><a href="class.htm">返回</a></p> </body> </html>
4 編寫IDC文件
示例.idc文件中數據源的名稱(Datasource)為“CLASS”。用戶名(Username)為sa、密碼(Password)未設,來保證到ODBC數據源的有效登錄,通常sa權限最高,它為係統默認的管理員。TEMPLATE模板指定用於輸出結果的相應HTX文件。SQL Statement是要執行的SQL語句。本例中四個SQL語句是從stu數據庫people表中選取NAME、AGE、SEX、PHONE、EMAIL字段,IDC對數據庫中的數據進行增加、修改、刪除和檢索等操作,並將結果通過相應的HTML擴展文件(.htx)輸出。
edit.idc|文件:
delete.idc文件:
search.idc文件:
5 編寫HTX文件
<form method="POST" action="edit.idc"> |