Attribute VB_Name = "mod_mysql"
Global QueryResults As String
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.command
Dim TempData As String
Public Function MySQLConnect()
On Error GoTo mysqlerror
cn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
           & "SERVER=localhost;" _
           & "DATABASE=chat;" _
           & "UID=root;" _
           & "PWD=;" _
           & "OPTION=3"
cn.Open
rs.ActiveConnection = cn
Exit Function
mysqlerror: MsgBox (Err.Description), vbCritical, "MySQL Error (000601)"
End
End Function
Public Function MySQLQuery(Query As String) As String
If rs.State = adStateOpen Then
rs.Close
End If
On Error Resume Next

rs.Open Query
MySQLQuery = rs.GetString
rs.Close
MySQLQuery = Mid(MySQLQuery, 1, Len(MySQLQuery) - 1)
Form3.StatusBar1.SimpleText = Query
Exit Function
errhandle:
MsgBox (Err.Description)
End Function
Public Function MySQLWrite(Query As String)
If rs.State = adStateOpen Then
rs.Close
End If
On Error Resume Next

rs.Open Query
Exit Function
errhandle:
MsgBox (Err.Description)
End Function
Public Function MySQLDelete(Query As String)
On Error Resume Next
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open Query
Exit Function
errhandle:
If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
End Function
Public Function MySQLCreate(Query As String)
On Error Resume Next
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open Query
Exit Function
errhandle:
If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
End Function
Public Function MySQLExists(Query As String) As Boolean
On Error Resume Next
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open Query
If rs.State = adStateClosed Then
MySQLExists = False
Exit Function
End If
If rs.EOF = False Then
MySQLExists = True
Else
MySQLExists = False
End If
rs.Close
Exit Function
errhandle:
If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
End Function
