OLEDB way to open the SQL data connection
Sub openSqlbyOLEDB
On error resume next
set conn = server.createObject (adodb.connection)
conn.open provider = sqloledb.1; Password = 'Sa'; Persist Security Info = TRUE; User ID = SA; Initial catalog = Gate; Data Source = (local);
If err.number <> 0 then
err.clear
Response.write (<div align = 'center'> The database is connected to an error, please contact the administrator! </Div>)
Response.end ()
End if
End sub
'Database operation -related functions
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] OpenReadrs RS, SQL, OTYPE
'Function: Open the corresponding type of data set and read only the operation
'parameter:
'RS open RS collection
'SQL statement executed
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Sub openreadrs (RS, SQL)
If not isObject (RS) then
Set rs = server.createObject (Adodb.oldSet)
RS.Oopen SQL, CONN, 1,1
End if
End sub
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] OpenWriters RS, SQL
'Function: Open the corresponding type of dataset, you can write the operation
'parameter:
'RS open RS collection
'SQL statement executed
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Sub openwriters (RS, SQL)
If not isObject (RS) then
Set rs = server.createObject (Adodb.oldSet)
RS.Oopen SQL, CONN, 1,3
End if
End sub
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] Endrs rs
'Function: Close the corresponding type of data set
'parameter:
'RS open RS collection
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Sub endrs (RS)
If isObject (RS) then
RS.Close: Set RS = Nothing
End if
End sub
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] Endconn
'Function: Close the database connection
'Parameter: none
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Sub endnn
If isObject (conn) then
conn.close: set conn = Nothing
End if
End sub
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] Execsql SQL
'Function: execute SQL statement
'parameter:
'SQL statement executed
'***********************************************************************************************************************************************************************************************************************************************************************, *************
SUB Execsql (SQL)
conn.execute (SQL)
End sub
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] selectalone sql
'Function: single field query
'parameter:
'SQL statement executed
'Return: query field value
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Selectalone (SQL)
DIM Selectaloners
Set selectaloners = const.execute (SQL)
Selectalone = Selectaloners (0)
Endrs Selectaloners
End
'String operation related functions
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] ISSAFESTR STR
'Function: Determine whether it is safe string, use in special fields such as registration and login
'parameter:
'STR string to detect
'Return: true = security, false = unsafe
'***********************************************************************************************************************************************************************************************************************************************************************, *************
ISSAFESTR (STR)
Dim s_badstr, n, i
s_badstr = '& <>?%,;: () ~!@#$^*{} [] |+-= & chr (34) & chr (9) & chr (32)
n = len (s_badstr)
ISSAFESTR = TRUE
For i = 1 to n
If Instr (STR, MID (S_badstr, I, 1))> 0 THEN
ISSAFESTR = FALSE
Exit
End if
Next
End
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] HTMLTOENCode Str
'Function: Code HTML
'parameter:
'STR needs to encode a string
'Return: Code string
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Htmltoencode (STR) '
if not isnull (str) and str <> then
str = replace (str, &, & amp;)
str = replace (str,>, & gt;)
str = replace (str, <, & lt;)
Str = replace (str, chr (32),)
str = replace (str, chr (9), & nbsp;)
str = replace (str, chr (34), & quot;)
Str = Replace (str, chr (39), ')
str = replace (str, chr (13),)
Str = Replace (STR,, s CRIPT)
Str = Replace (Str, s ;, s)
Htmltoencode = STR
end if
End
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] ENCODETOHTML Str
'Function: Code HTML Code
'parameter:
'STR needs to be coded string
'Return: Reverse -coded string
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Encodetohtml (STR)
if not isnull (str) and str <> then
str = replace (str, & amp;,, &)
str = replace (str, & gt ;,>)
str = replace (str, & lt ;, <)
Str = Replace (STR,, CHR (32))
str = replace (str, & nbsp ;, chr (9))
Str = Replace (Str, & Quot ;, chr (34))
str = replace (str, ' ;, chr (39))
Str = Replace (STR,, CHR (13))
str = replace (str, s cript,)
Str = Replace (Str, s ;, s)
Encodetohtml = STR
end if
End
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] Gottopic Str, Strlen
'Function: Test the length of the string stroln, Chinese characters are calculated 2 length
'parameter:
'STR needs to be intercepted
'Strlen intercept length
'Return: The string after the length of the Strlen length
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Gettopic (Str, Strlen)
if str = then
Gottopic =
exit
end if
dim l, t, c, i
l = len (STR)
T = 0
for i = 1 to l
C = ABS (ASC (MID (STR, I, 1)))))
if c> 255 then
t = t+2
else
t = t+1
end if
if t> = strlen then
Gottopic = left (str, i) & ...
exit for
else
Gottopic = STR
end if
next
End
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] DateFormattime TVar, style
'Function: Time formatting
'parameter:
'TVar needs formatting time string
'STYPE formatting type
'Return: Formatting time string
'***********************************************************************************************************************************************************************************************************************************************************************, *************
DateFormattime (TVAR, style)
dim TT, Syear, SMNON, SDAY, SHOUR, Sminute, SSECOND
If not isdate (TVAR) then dateformattime =: exit
Tt = TVar
Syear = year (tt)
Smonth = Right (0 & Month (TT), 2)
SDAY = RIGHT (0 & Day (TT), 2)
Shour = Right (0 & Hour (TT), 2)
Sminute = Right (0 & minute (TT), 2)
ssecond = Right (0 & sex (TT), 2)
Select case style
Case 1'2006-3-13
DateFormattime = Syear & -& SMONTH & -& SDAY
Case 2 'March 13, 2006
DateFormattime = Syear & Year & SmNth & Monthly & SDAY & Day
case 3 '2006031313120123
DateFormattime = Syear & SMONTH & SDAY & Shour & Sminute & SSECOND
Case Else
DateFormattime = TT
End select
End
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] Isnum str
'Function: Whether it is a number
'parameter:
'STR needs to judge string
'Return: true = number, false = non -numbers
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Isnum (Str) '
if Str <> and Isnumeric (Str) then
Isnum = TRUE
else
Isnum = false
end if
End
'Output debugging related functions
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] Mesgoback Str
'Function: pop up information and return
'parameter:
'STR needs to judge string
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Sub Mesgoback (STR)
Response.write (<Language = 'Java'> Alert ('& Str &'); History.back (); </>)
Response.end ()
End sub
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] Mesgourl Str, URL
'Function: pop up information and return
'parameter:
'STR needs to judge string
'URL jump address
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Submesgourl (str, url)
Response.write (<Language = 'Java'> Alert ('& Str &'); local.href = '& url &'; </>)
Response.end ()
End sub
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[Sub] Debug Wrong
'Function: debug output
'parameter:
'Wrong wants output information
'Return: No return value
'***********************************************************************************************************************************************************************************************************************************************************************, *************
SUB Debug (ingRong) 'debug output
Response.write (ing)
Response.end ()
End sub
'Function -related functions
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] Getip
'Function: Get user IP
'parameter:
' none
'Return: User current IP
'***********************************************************************************************************************************************************************************************************************************************************************, *************
Getip ()
DIM Userip
userip = request.servervariables (http_x_Forwarded_For)
If userip = then userip = request.servervariables (remote_addr)
Getip = Userip
End
'***********************************************************************************************************************************************************************************************************************************************************************, *************
'[] geturl
'Function: Get the current domain name
'parameter:
' none
'Return: The current domain name
'***********************************************************************************************************************************************************************************************************************************************************************, *************
geturl ()
getUrl = Request.servervariables (Server_name)
End