JS program's function has a general framework, in fact, you can add some features, such as the beginning of the database connection, you can first set
Variable and then use init () to select a different type of database
<%
' On Error Resume Next
Class Connex
Public Connex
Public dbpath '---------database path
Public DBtype '---------database type 1 (Access) 2 (SQL Server) 3 (expandable)
Public Connmethod '--------connection mode (DSN, non-DSN)
Public User
Public Pass
Sub Class_Initialize
End Sub
Sub Init ()
ConnStr = "Driver={microsoft Access Driver (*.mdb)};d bq=" &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 ("Catch error, end of program!" at "&Str&")
Response.End ()
End If
End Sub
’******************************************
' * Using SQL statements to find out if a record is present, error prone
’******************************************
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
’***************************************
' * To find out if a record exists by 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
’**********************************************
' * Get a Recordset from SQL statement
’**********************************************
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
’*********************************************
' * Get the value of a field
’*********************************************
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 = "no Record"
End If
Rs.close
Set Rs = Nothing
Getvaluebysql = returnvalue
End Function
' ==================================================update,insert===================================
’*********************************************
' * Using SQL to modify data
’*********************************************
Function Updatebysql (SQL)
Call Checksql (SQL, "w")
Connex.execute (SQL)
Catcherror ("Updatebysql")
Updatebysql = True
End Function
’********************************************
' * INSERT data using SQL statements
’********************************************
Function Insertbysql (SQL)
Call Checksql (SQL, "w")
Connex.execute (SQL)
Catcherror ("Insertbysql")
Insertbysql = True
End Function
' ======================================================delete========================================
’********************************************
' * deleted by SQL statement
’********************************************
Function Deletebysql (SQL)
Call Checksql (SQL, "D")
Connex.execute (SQL)
Catcherror ("Deletebysql")
Deletebysql = True
End Function
’********************************************
' * Check SQL statement permissions, detect the permissions of statements based on flag 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 syntax error!")
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 ("Insufficient permissions, no permissions to perform write operations")
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 ("Insufficient permissions, no permission to perform a delete operation")
Response.End ()
End If
Case "D", "D":
Case Else:
Response.Write ("function Checksql flag Error!")
End Select
End Sub
Sub Class_Terminate
If not IsEmpty (friendconn) Then
Friendconn.close
Set Friendconn = Nothing
Catcherror ()
End If
End Sub
End Class
%>