|
|
|
利用jsp的思想来做asp |
|
|
| http://www.iyit.net 日期:2005-11-24 17:25:59 来源:易特网络技术 点击: |
程序的功能有了个大体的框架,其实可以自己添加一些功能,比如开始的数据库连接 ,可以先设置变量然后通过init() 来选择不同类型的数据库 <% ’on error resume next class connex public connex public dbpath ’---------数据库路径 public dbtype ’---------数据库类型 1(access) 2(sqlserver) 3(可扩充) public connmethod ’--------连接方式 (dsn,非dsn) public user public pass sub class_initialize end sub
sub init() connstr = "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("date.mdb") set connex = server.createobject("adodb.connection") connex.open connstr catcherror("class_terminate") end sub
sub catcherror( str ) if err then err.clear class_terminate() response.write("捕捉到错误,程序结束!在"&str&"处") response.end() end if end sub
’****************************************** ’*通过sql语句来查找记录是否存在,容易出错 ’******************************************
function hasrecordbysql( sql ) call checksql(sql,"r") dim rs,hasr set rs = connex.execute( sql ) catcherror("hasreordsql") if not (rs.eof or rs.bof) then hasr = false else hasr = true end if rs.close set rs = nothing hasrecordbysql = hasr end function
’*************************************** ’*通过id来查找记录是否存在 ’***************************************
function hasrecordbyid( strtablename , intid ) ’checkvalue( intid , 1 ) dim rs,hasr sql = "select top 1 * from "&strtablename&" where id = "&intid call checksql(sql,"r") set rs = connex.execute(sql) catcherror("hasrecordbyid") if not (rs.eof or rs.bof) then hasr = false else hasr = true end if rs.close set rs = nothing hasrecordbyid = hasr end function
’********************************************** ’*通过sql语句取得记录集 ’********************************************** function getrsbysql( sql ) call checksql(sql,"r") dim rs set rs = server.createobject("adodb.recordset") rs.open sql,connex,1,1 set getrsbysql = rs end function
’********************************************* ’*取得某个字段的值 ’********************************************* function getvaluebysql( sql ) call checksql(sql,"r") dim rs,returnvalue set rs = connex.execute(sql) catcherror("getvaluebysql") if not( rs.eof or rs.bof ) then returnvalue = rs(0) else returnvalue = "没有记录" end if rs.close set rs = nothing getvaluebysql = returnvalue end function
’==================================================update,insert==================================================================
’********************************************* ’*利用sql修改数据 ’********************************************* function updatebysql( sql ) call checksql(sql,"w") connex.execute(sql) catcherror("updatebysql") updatebysql = true end function
’******************************************** ’*利用sql语句插入数据 ’******************************************** function insertbysql(sql) call checksql(sql,"w") connex.execute(sql) catcherror("insertbysql") insertbysql = true end function
’======================================================delete=============================================================
’******************************************** ’*通过sql语句删除 ’******************************************** function deletebysql( sql ) call checksql(sql,"d") connex.execute(sql) catcherror("deletebysql") deletebysql = true end function
’******************************************** ’*检查sql语句权限,根据标志flag 来检测语句拥有的权限 ’******************************************** sub checksql( sql , flag ) dim strsql,sincounts,doucounts,i strsql = lcase(sql) sincounts = 0 doucounts = 0 for i = 1 to len(strsql) if mid(strsql,i,1) = "’" then sincounts = sincounts + 1 if mid(strsql,i,1) = """" then douconnts = doucounts + 1 next
if (sincounts mod 2) <> 0 or (doucounts mod 2) <> 0 or instr(strsql,";") > 0 then call class_terminate() response.write("sql语法错误!") response.end() end if select case flag case "r","r": if instr(strsql,"delete") > 0 or instr(strsql,"update") or instr(strsql,"drop") > 0 or instr(strsql,"insert") > 0 then class_terminate() response.write("权限不足,没有执行写操作的权限") response.end() end if case "w","w": if instr(strsql,"delete") > 0 or instr(strsql,"drop") > 0 or instr(strsql,"select") > 0 then class_terminate() response.write("权限不足,没有执行删除操作的权限") response.end() end if case "d","d": case else: response.write("函数checksql标志错误!") end select end sub
sub class_terminate if not isempty(friendconn) then friendconn.close set friendconn = nothing catcherror() end if end sub end class %>
|
上一篇:轻松实现将上传图片到数据库
下一篇:动网论坛代码分析
[发送给好友] [打印本页] [关闭窗口] [返回顶部] 转载请注明来源:http://www.iyit.net |
|
| 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
| 责任编辑: |
投稿作者: 易特网络技术 |
| 信息来源: 易特网络技术 |
录入时间: 2005-11-24 17:25:59 |
| 浏览次数: |
投稿信箱: shtghy@163.com |
|
|
|
|
|