現(xiàn)在很多人用Access數(shù)據(jù)庫實(shí)現(xiàn)文章顯示系統(tǒng),由于Access數(shù)據(jù)庫本身的缺陷,用一個字段存放文章內(nèi)容,我以為對于訪問量 大,文章數(shù)目多的網(wǎng)站,很容易產(chǎn)生錯誤,此舉是極不明智的,經(jīng)過實(shí)際比較,筆者得出另一種實(shí)現(xiàn)文章系統(tǒng)的方法,那就是采 用Access+文本文件 的模式.其中Access數(shù)據(jù)庫用來存每篇文章的一般信息,而文本文件用來存放具體文章內(nèi)容.具體實(shí)現(xiàn)方 法實(shí)現(xiàn)如下: 先用Access建立一個數(shù)據(jù)庫wzozg,里面只有一個表ozg,存放文章一般信息,字段如下: 字段名 類型 含義 wid 自動編號 文章id號 wsubject 文本 文章標(biāo)題 wname 文本 存放文章內(nèi)容的文本文件名 wcount 數(shù)字 文章訪問次數(shù) wdate 時間 文章加入時間 wauth 文本 文章作者 wsource 文本 文章來源 '其中wid與wname唯一對應(yīng),如wid=10,則wname="wz-10.asp",若wid=n,則wname="wz-n.asp" 以下是文章添加,刪除,以及實(shí)現(xiàn)文章標(biāo)題列表顯示,每篇文章具體內(nèi)容顯示的關(guān)鍵代碼段: 1.文章添加 1)wzadd.html <form method="post" action="add.asp">
<p>文章標(biāo)題:<input name="isubject" size="45" maxlength="30"></p>
<p>文章作者:<input name="iauth" size="45" maxlength="30"></p>
<p>文章來源:<input name="isource" size="45" maxlength="30"></p>
<p>文章內(nèi)容:</p> <textarea cols="80" name="icontent" rows="16"wrap="VIRTUAL"></textarea></p>
<p><input type="submit" value="完 成" name="submit"> <input type="reset" value="重 寫" name="reset"></p> </form>
2)add.asp <%sj=now() '返回系統(tǒng)時間
isubject= Request.Form("isubject") icontent = Request.Form("icontent") iauth= Request.Form("iauth") isource = Request.Form("isource")
dim xwzlr() n=0 for i = 1 to len(icontent) zh =mid(icontent,i,1) xzh=server.htmlencode(zh) '使字符不支持html語法 redim preserve xwzlr(n) xwzlr(n)=lrtemp '使add.html中表單form中textarea一行一行分別存在數(shù)組中 if asc(xzh)=10 then n=n+1 lrtemp="" redim preserve xwzlr(n) end if lrtemp = lrtemp + zh next '連接數(shù)據(jù)庫 set dbconn=server.createobject("adodb.connection") conpath="DBQ=" &server.mappath("wzozg.mdb") dbconn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & conpath '新增文章 iozg="wz-" sql="INSERT INTO ozg(wsubject,wname,wcount,wdate,wauth,wsource) Values ('"&isubject&"','"&iozg&"',0,'"&sj&"','"&iauth&"','"&isource&"')" dbconn.Execute(sql)
sql="update ozg set wname='wz-'&cstr(wid)&'.asp' " '若文章id=n (n=0,1,2,...),則使 存放文章內(nèi)容的文本文件 名為 "wz-n.asp",即id號與文本文件名唯一對應(yīng) dbconn.Execute(sql) sql="select wcontent from ozg " set rs=server.createobject("adodb.recordset") rs.open sql,dbconn,3,1 rs.movelast iozg=rs("wcontent") '獲取文本文件名"wz-n.asp" rs.close dbconn.Close thisfile = server.mappath(iozg) Set fs=Server.CreateObject("Scripting.FileSystemObject") Set outfile = fs.CreateTextFile(thisfile) '創(chuàng)立文本文件"wz-n.asp" (n=0,1,2,...) for i=0 to n step 1 outfile.WriteLine xwzlr(i) '把數(shù)組中的文章內(nèi)容逐行寫入文本文件"wz-n.asp"中 next outfile.close set fs=nothing %> --------------------------------------------------- (出處:熱點(diǎn)網(wǎng)絡(luò))
|