欢迎光临
我们一直在努力

缓存类及打开数据库连接函数-ASP教程,ASP技巧

建站超值云服务器,限时71元/月

懒人的作品,我连长一点点的代码,都写成函数了。。。

用起来,可以偷懒,哈哈。。。

<%@ language = vbscript codepage = 936

dim jz

set jz=new jz_clsmain

jz.cache_count=0

jz.web_name="华人中小企业资源网"

class jz_clsmain

public rs,conn,sql,db

public web_name,t,t_s,t_h,cache

public i_0,i_1

public reloadtime,cachename,localcachename,cache_data,cache_count

private sub class_initialize()

redim db(4),conn(4),rs(4),sql(4)

redim t(20,4),t_s(20,3)

reloadtime=14400*60

cachenamecachename=replace(replace(replace(server.mappath("/"),"/",""),":",""),"\","")

cachename=request.servervariables("url")

cachename=left(cachename,instrrev(cachename,"/"))&"jz"

cache_count=1000

web_name="匠族"

end sub

private sub class_terminate()

i_1=lbound(db)

for i_0=0 to i_1

on error resume next

response.write(i_0&"<br/><br/>")

if isobject(rs(i_0)) then rs(i_0).close:set rs(i_0)=nothing

if isobject(conn(i_0)) then conn(i_0).close:set conn(i_0) = nothing

next

end sub

public function tree_00(str_0)

dim i,jz_temp(1)

for i=0 to str_0

jz_temp(0)=jz_temp(0)&jz_temp(1)

jz_temp(1)="../"

next

tree_00=jz_temp(0)

end function

public function conn_00(str_0,str_1)

str_1=tree_00(str_1)

db(str_0)="provider = microsoft.jet.oledb.4.0;data source = " & server.mappath(str_1&"data/data_"&str_0&".mdb")

response.write(db(str_0))

end function

str0=0-4<定义选择的db(str0),并定义conn(str0)及rs(str0)>;str1=true,false<是否创建数据库连接>;str2=true,false<是否创建rs对象>;

public function c_r_s(str0,str1,str2)

on error resume next

if str1 then

set conn(str0) = server.createobject("adodb.connection")

conn(str0).open db(str0)

end if

if str2 then

set rs(str0) = server.createobject( "adodb.recordset" )

end if

end function

public function c_r_o(str0,str1,str2)

rs(str0).open sql(str0), conn(str0), str1, str2

if err then

err.clear

set conn(str0) = nothing

response.write "数据库连接出错,请检查连接字串。"注释,需要把这几个字翻译成英文。

response.end

end if

end function

public function c_r_e(str0,str1,str2)

on error resume next

if str2 then

rs(str0).close

set rs(str0)=nothing

end if

if str1 then

conn(str0).close

set conn(str0)=nothing

end if

end function

public property let name(byval vnewvalue)

localcachename = lcase(vnewvalue)

end property

public property let value(byval vnewvalue)

if localcachename<>"" then

redim cache_data(2)

cache_data(0)=vnewvalue

cache_data(1)=now()

cache_data(2)=reloadtime

application.lock

application(cachename & "_" & localcachename) = cache_data

application.unlock

else

err.raise vbobjecterror + 1, "jzcacheserver", " please change the cachename."

end if

end property

public property get value()

if localcachename<>"" then

cache_data=application(cachename & "_" & localcachename)

if isarray(cache_data) then

value=cache_data(0)

else

err.raise vbobjecterror + 1, "jzcacheserver", " the cache_data("&localcachename&") is empty."

end if

else

err.raise vbobjecterror + 1, "jzcacheserver", " please change the cachename."

end if

end property

public function objisempty()

app_count()

objisempty=true

cache_data=application(cachename & "_" & localcachename)

if not isarray(cache_data) then exit function

if not isdate(cache_data(1)) then exit function

if isempty(cache_data(2)) then exit function

if datediff("s",cdate(cache_data(1)),now()) < (cache_data(2)) then objisempty=false

end function

public sub delcahe(mycahename)

application.lock

application.contents.remove(cachename&"_"&mycahename)

application.unlock

end sub

public sub app_count()

if application.contents.count>cache_count then

application.lock

application.contents.removeall()

application.unlock

end if

end sub

function fso_000(str0)

dim jz_cache,jz_fso,jz_path,jz_file

set jz_fso = server.createobject("scripting.filesystemobject")

jz_path = server.mappath(str0)

response.write(jz_path)

set jz_file = jz_fso.opentextfile(jz_path, 1)

do until jz_file.atendofstream

jz_cache=jz_cache&jz_file.readline&vbcrlf

loop

fso_000=jz_cache

jz_file.close

set jz_file = nothing

set jz_fso = nothing

end function

sub replace_000(str0)

t_h=replace(t_h,str0,cache&"")

t_empty()

end sub

sub t_empty()

for i_0=0 to 20:for i_1=0 to 4

t(i_0,i_1)=empty

next:next

i_0=empty

i_1=empty

cache=empty

end sub

public function target(jz_target)

select case jz_target

case 0

jz_target=""

case 1

jz_target="target=""new"""

end select

target=jz_target

end function

end class

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 缓存类及打开数据库连接函数-ASP教程,ASP技巧
分享到: 更多 (0)