asp(vbscript)数据库操作类

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

<%
'数据库操作类
'asp 版本  gb2312
'制作:伤心的歌 QQ:369758482  url:http://www.q128.net

'On Error Resume Next

class data

  public sub w(vals)
   Response.Write(Replace(vals,"\n",vbcrlf))
  end sub

  public sub memsg(txt,urls)
   if urls="" then urls="javascript:history.back();"
   if txt<>"" then
    Response.Write("<script type='text/javascript'>alert('"&txt&"');document.location='"&urls&"';</script>")
   else
    Response.Redirect(urls)
   end if
	Response.End()
  end sub
  
  public db,loca,locauser,locapass,locadata,connstr,conn,rs,stype,sql,page_size,pagenum
  
  public Sub Database()
     if stype=1 then
	  connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db) & ""
	 else
	  connstr="Provider=SQLOLEDB.1;Password='"&locapass&"';Persist Security Info=True;User ID='"&locauser&"';Initial Catalog='"&locadata&"';Data Source='"&loca&"'" 
	 end if
	 
	 
	    Set conn=Server.CreateObject("ADODB.Connection")
	    conn.open connstr
      if err then
	   Response.Write("数据库连接错误,请检查数据库参数")
	   Response.End()
	  end if
      
  end Sub
  

  
  public Sub Record(fielder,table,Condition,sorts,ty,fenye)
   if fielder="" then fielder="*"
     sql="select "&fielder&" from "&table
   if Condition<>"" then sql=sql&" where "&Condition
   if sorts    <>"" then sql=sql&" order by "&sorts
   
     Set rs=Server.CreateObject("ADODB.recordset")
	  if fenye then
         pagenum=cint(Request.QueryString("page"))
	   if pagenum="" or not isnumeric(pagenum) or pagenum<1 then pagenum=1
	 
       rs.cachesize=page_size
       rs.cursortype=1	 
	 end if
	   
	  if ty=1 then
	   rs.open sql,conn,1,1
	  elseif ty=2 then
	   rs.open sql,conn,1,2
	  elseif ty=3 then 
	   rs.open sql,conn,1,3
	  end if
	  
	 if fenye then
       rs.pagesize=page_size
        if pagenum>rs.pagecount then pagenum=rs.pagecount
        if not rs.eof then rs.absolutepage=pagenum 
	 end if
	   
  
  end sub
  
  public function ps(tf)
   if tf then
    ps=rs.pagesize
   elseif not tf then
     if rs.eof then
	  ps=true
	   else
	  ps=false
	 end if
   end if
  end function
  
  
  public function show(val)
    show=rs(val)
  end function
  
  public sub pagehtml(a,b,c)
   if pagenum=1 then
     Response.Write replace(replace(replace(a,"$1","javascript:"),"$2","dis"),"$3","首页")
     Response.Write replace(replace(replace(a,"$1","javascript:"),"$2","dis"),"$3","上一页")
	  else
     Response.Write replace(replace(replace(a,"$1","?page=1"),"$2","ok"),"$3","首页")
     Response.Write replace(replace(replace(a,"$1","?page="&pagenum-1&""),"$2","ok"),"$3","上一页")
   end if
   
   f=1
   g=10
   if g>rs.pagecount then g=rs.pagecount
   if pagenum>9 then
     f=pagenum-1
	 g=pagenum+9
   end if
   if g>rs.pagecount then
    f=rs.pagecount-10
	g=rs.pagecount
   end if
   
  for i=f to g
   if i=pagenum then
     Response.Write replace(b,"$1",i)
    else
     Response.Write replace(replace(replace(a,"$1","?page="&i&""),"$2","ok"),"$3",i)
	end if
  next
  
   if pagenum=rs.pagecount then
     Response.Write replace(replace(replace(a,"$1","javascript:"),"$2","dis"),"$3","下一页")
     Response.Write replace(replace(replace(a,"$1","javascript:"),"$2","dis"),"$3","尾页")
	  else
     Response.Write replace(replace(replace(a,"$1","?page="&pagenum+1&""),"$2","ok"),"$3","下一页")
     Response.Write replace(replace(replace(a,"$1","?page="&rs.pagecount&""),"$2","ok"),"$3","尾页")
   end if
   
    Response.Write replace(c,"$1","共"&rs.recordcount&"条记录")
	Response.Write replace(c,"$1","共"&rs.pagecount&"页")
	Response.Write replace(c,"$1","当前第"&pagenum&"页")
  end sub
  
  public function p(vas,y,f)
   if y=1 then
    mmm=Request.Form(vas)
   elseif y=2 then
    mmm=Request.QueryString(vas)
   end if
  if f=1 then
	 if mmm<>"" and mmm=1 and isnumeric(mmm) then
	   p=true
	  else
	   p=false
	 end if
	mmm=""
   else
    p=mmm
   end if
  end function
  
  public sub add()
    rs.addnew
  end sub
  
  public Sub into(jian,val)
    rs(jian)=val
   rs.update
  end Sub
  
  public sub del(tab,whe)
   sql="delete from "&tab
   if whe<>"" then sql=sql&" where "&whe
    conn.execute sql
  end sub 
  
  public function x()
     x=rs.recordcount
  end function
  
  public sub nex()
   rs.movenext
  end sub
  
  public sub ul()
    rs.close
   Set rs=nothing
    sql=null
  end Sub 
  
  public Sub cn()
    conn.close
   Set conn=nothing
  end Sub
  
  public function nullys(ys)
   nullys=true
   if ys="" then 
     nullys=false
   end if
  end function
  
  public function rep(values,out)
    if Request.Form(values)="" then 
      rep=out
	   else
	  rep=Request.Form(values)
	end if
  end function
  
end class
%>