asp实现简单数据库连接类
实现了简单的数据库连接,得到记录集,得到二维数组,执行某个语句,其实这个类可以继续扩充,比如先读取变量,得到执行次数,简单分页等等。。,篇幅有限,自己扩充
'----------------------------------------------
'数据库操作
'----------------------------------------------
'简化的数据类
Class dbconn
public connstr,conn,queryCount,die_err
private connstate
Private Sub Class_Initialize
queryCount=0
connstate = false
die_err = true
End Sub
'构造
Sub Conn_Open
on error resume next
set conn = server.CreateObject("adodb.connection")
conn.connectiontimeout = 120
Conn.Open connstr
if err then
if die_err = true then die "数据库连接错误!"
else
connstate= true
end if
End Sub
'得到记录集
Function getRs(byval sqlStr,byval vtype)
On Error Resume Next
if cint(vtype) <> 3 then vtype =1 end if
if connstate = false then call Conn_Open
set getrs = server.CreateObject("ADODB.RECORDSET")
getrs.open sqlStr,conn,1,vtype
queryCount = queryCount+1
if Err then
if die_err = true then die sqlStr
if die_err = true then die "数据库得到记录集错误!"
end if
End Function
'得到单一的值
Function getVal(byval sqlstr)
On Error Resume Next
if connstate = false then call Conn_Open
dim rs : set rs =conn.execute(sqlstr)
if rs.eof then
getVal =""
else
getVal = rs(0)
end if
rs.close : set rs = nothing
End Function
Function exec(Byval sqlstr)
if connstate = false then call Conn_Open
conn.execute(sqlstr)
End Function
'得到数组
Function getArray(Byval sqlstr)
on error resume next
if connstate = false then call Conn_Open
dim rs : set rs =conn.execute(sqlstr)
if rs.eof then getArray = "" else getArray = rs.getrows
rs.close : set rs = nothing
queryCount = queryCount+1
if Err then
if die_err = true then die "数据库得到数组错误!"
end if
End Function
'析构
Public Sub Class_Terminate()
if connstate = true
相关文档:
书接上文,直接从字符串返回对象,此次更新,实现了返回对象的自动化,无需在声明实体类。但这个函数只适合页面声明几个对象,批量对象,比如几百个,推荐使用下一文所使用函数。
函数很简单,不解释,直接贴代码。
option explicit
'返回对象的函数
function getObj(byval str)
dim classname,itemlist,i
cl ......
option explicit
dim str1,str2
str1 ="order|||shiyang:100,mayang:200"
str2 = "book|||shuming:计算机,dingjia:100"
'声明2个全局对象
'放弃了一开始希望用数组存储的方式,那个虽然效率更高,但是需要自定义的array_pushobj函数,所以此处不做讨论了
dim objname_g
dim classname_g
'返回实体类
function getO ......
最近有很多的朋友问到调用存储过程的问题,这里简单介绍几种ASP调用带参数存储过程的方法。
1. 这也是最简单的方法,两个输入参数,无返回值:
set connection = server.createobject("adodb.connection")
connection.open someDSN
Connection.Execute "procname varvalue1, varvalue2"
'将所 ......
GUID概述
Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique
IDentifier)
GUID/UUID是通过特定算法产生的一个二进制长度为128位的数字。
在空间上和时间上具有唯一性,保证同一时间不同地方产生的数字不同。
世界上的任何两台计算机都不会生成重复的 GUID 值。GUID 主要用于在拥有多个节 ......