📄 function.asp
字号:
<%
' 数据库对象
function dbinit()
if not Isobject(conn) then
dim connstr
select case lcase(databasetype)
case "access"
connstr = "Provider=Microsoft.Jet.OLEdb.4.0;Data Source=" & server.mappath(databaseaccesspath)
case "mssql"
if len(databaseport) > 0 then databaseserver = databaseserver & "," & databaseport
connstr = "Provider=Sqloledb;Data Source=" & databaseserver & ";Initial Catalog=" & databasename & ";User ID=" & databaseuser & ";Password=" & databasepass & ";"
case "mysql"
if len(databaseport) > 0 then databaseserver = databaseserver & ";Port=" & databaseport
connstr = "Driver={MySQL OdbC 3.51 Driver};Server=" & databaseserver & ";database=" & databasename & ";User=" & databaseuser & ";Password=" & databasepass & ";"
case else
response.write "配置出错!": response.end
end select
on error resume next
set conn = server.createobject("adodb.connection")
conn.open connstr
if err then
response.write "数据库链接出错,请检查数据库路径是否正确(Conn.asp)!"&err.description
err.clear
response.end
end if
end if
end function
' 数据库操作
function db(byval sqlstr,byval sqltype)
sqlstr = replace(sqlstr, "{pre}", databasePrefix)
select case lcase(databaseType)
case "access"
sqlstr = replace(sqlstr, "{date}", "now()")
case "mssql"
sqlstr = replace(sqlstr, "{date}", "GetDate()")
case "mysql"
sqlstr = replace(sqlstr, "{date}", "CURRENT_DATE()")
sqlstr = replace(replace(sqlstr, "[", "`"), "]", "`")
if instr(lcase(sqlstr), "select top") > 0 then
dim reg : set reg = new regexp : reg.ignorecase = true : reg.global = true
reg.pattern = "(select top )([0-9]+)"
dim toplimit : set toplimit = reg.execute(sqlstr)
if toplimit.count > 0 then sqlstr = replace(sqlstr, toplimit(0), "select ") & " limit " & toplimit(0).toplimit(1)
end if
sqlstr = sqlstr & ";"
end select
' response.write sqlstr & vbcrLf & "<BR>" & vbcrLf
call dbinit
select case sqltype
case 0
conn.Execute (sqlstr)
case 1
set db = conn.execute(sqlstr)
case 2
set db = server.createobject("Adodb.Recordset")
db.open sqlstr, conn, 1, 1
case 3:
set db = server.createobject("Adodb.Recordset")
if lcase(databaseType) = "mysql" then
db.Activeconnection = conn
db.Source = sqlstr
db.CursorType = 3
db.CursorLocation = 3
db.lockType = 3
db.open()
else
db.open sqlstr, conn, 1, 3
end if
end select
end function
sub showpage(totalnumber,maxperpage,ShowTotal,ShowAllPages,strUnit)
Dim query, a, x, temp, action
action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")
query = Split(Request.ServerVariables("QUERY_STRING"), "&")
For Each x In query
a = Split(x, "=")
If StrComp(a(0), "page", vbTextCompare) <> 0 Then
temp = temp & a(0) & "=" & a(1) & "&"
End If
Next
dim n, i,strTemp,strUrl
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
strTemp= "<DIV class=black2>"
strTemp=strTemp & "<SPAN>页次:" & Page & "/" & n & " </SPAN>"
if Page<2 then
strTemp=strTemp & "<SPAN class=disabled>首页</SPAN>"
strTemp=strTemp & "<SPAN class=disabled>上一页</SPAN>"
else
strTemp=strTemp & "<a href='"& action & "?" & temp & "Page=1'>首页</a>"
strTemp=strTemp & "<a href='"& action & "?" & temp & "Page=" & (Page-1) & "'>上一页</a>"
end if
if n-Page<1 then
strTemp=strTemp & "<SPAN class=disabled>下一页</SPAN>"
strTemp=strTemp & "<SPAN class=disabled>末页</SPAN>"
else
strTemp=strTemp & "<a href='" & action & "?" & temp & "Page=" & (Page+1) & "'>下一页</a>"
strTemp=strTemp & "<a href='" & action & "?" & temp & "Page=" & n & "'>末页</a>"
end if
strTemp=strTemp & "<SPAN>" & maxperpage & "" & strUnit & "/页 </SPAN>"
if ShowTotal=true then
strTemp=strTemp & "<SPAN>共" & totalnumber & "" & strUnit & " </SPAN>"
end if
if ShowAllPages=True then
strTemp=strTemp & "<SPAN><form name='page-jump' id='pagejump'><input name='page' type='text' id='page' maxlength='5'><input name='go' type='button' id='go' value='GO' onclick='var intstr=/^\d+$/;if(intstr.test(pagejump.page.value)&&pagejump.page.value<=1&&pagejump.page.value>=2){location.href='" & action & "?" & temp & "Page=' + pagejump.page.value + '';}'></form></SPAN>"
end if
strTemp=strTemp & "</div>"
response.write strTemp
end Sub
'错误返回函数
Sub goerror(ErrStr,Going)
if Going="1" then
Response.Write "<Script>alert('"& ErrStr &"');location.href='javascript:history.go(-1)';</Script>"
Response.End
else
Response.Write "<Script>alert('"& ErrStr &"');location.href='"& Going &"';</Script>"
Response.End
end if
End Sub
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -