Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''''''''''''''''''''
- '' DATABASE CLASS ''
- ''''''''''''''''''''
- Class DBMySQLClass
- Private ConnectionString
- Private DB
- Public QueryCount
- Public OpenTime
- Private Sub Class_Initialize()
- Set DB = CreateObject("ADODB.Connection")
- End Sub
- Private Sub Class_Terminate()
- Me.Close
- Set DB = Nothing
- End Sub
- ' Create
- '
- Public Sub Setting(Hostname,Database,Username,Password)
- ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};SERVER="&Hostname&";DB="&Database&";USER="&Username&";PASSWORD="&Password&";OPTION=3;"
- End Sub
- ' Reset
- ' Reset connection to database
- Public Sub Reset()
- Me.Close
- Set DB = Nothing
- Set DB = CreateObject("ADODB.Connection")
- End Sub
- ' Connect
- ' Setup connection to SQL server.
- Private Sub Connect()
- If DB.ConnectionString = "" Then
- DB.ConnectionString = ConnectionString
- End If
- End Sub
- ' Open
- ' Open the MySQL connection
- Public Sub Open()
- If DateDiff("s",OpenTime,Now()) > 180 Then Close
- If Not CBool(DB.State) Then
- Connect
- DB.Open
- OpenTime = Now
- End If
- End Sub
- ' Close
- ' Close the MySQL connection
- Public Sub Close()
- If CBool(DB.State) Then
- DB.Close
- End If
- End Sub
- ' Query
- ' Execute a SQL query
- Public Function Query(SQL)
- StartTimer("query")
- Open
- Set Query = DB.Execute(SQL)
- Call EndTimer("query",SQL)
- End Function
- ' Count
- ' Returns result count.
- ' Note: resets pointer, so besure to save result count to a variable
- Public Function Count(Result)
- If Result.EOF AND Result.BOF Then
- Count = 0
- Else
- Result.MoveFirst
- While Not Result.EOF
- Count = Count + 1
- Result.MoveNext
- Wend
- Result.MoveFirst
- End If
- End Function
- ' EscapeString
- ' Converts a string into a SQL escaped string.
- ' Important to use this to reduce SQL injection exploitations.
- Public Function EscapeString(ES)
- EscapeString = Array_Replace(ES,Array("\","'","""",vbNewLine,vbCr,vbLf,vbTab),Array("\\","\'","\""","\n","","\n","\t"),1,-1,vbBinaryCompare)
- End Function
- ' WildCard
- ' Convert VB's usual wildcard to MySQL wildcard.
- Public Function Wildcard(WC)
- Wildcard = Replace(WC,"*","%")
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement