MySQL Connection "Objects"... Just a quick one (I think).
OK, Im making a server, nothing too fancy, (For now), which people can chat in...
and in it, im using MySQL (Until i get round to learning MS Access & PHP)..
Any howz,
With this code:
VB Code:
Public Sub LogOff(ConIndex As Integer, txtLog As RichTextBox)
On Error GoTo ErrorSub:
' Just make a log message
txtLog.SelStart = Len(txtLog.Text)
txtLog.SelColor = vbBlack
txtLog.SelText = Now & ":" & vbTab & "User Logged Out (Connection: " & ConIndex & ");" & vbCrLf
' Dim the stuff to use in this "Sub"
Dim oConn As New ADODB.Connection, oConn2 As New ADODB.Connection
Dim myRS As New ADODB.Recordset, myRS2 As New ADODB.Recordset
Dim UName As String, LocURL As String
' Set the connection to the database
oConn.Open "Driver={mySQL};" & _
"Server=" & MySQLServer & ";" & _
"Port=" & MySQLPort & ";" & _
"Option=131072;" & _
"Stmt=;" & _
"Database=" & ServerDB & ";" & _
"Uid=" & MySqlUID & ";" & _
"Pwd=" & MySqlPass & ";"
Set myRS = oConn.Execute("SELECT Username, LocationURL FROM online WHERE ConIndex='" & ConIndex & "'")
' We need to use these, to notify the room people, of the leaving.
' But we are gonna delete the user from the DB, so we need to get the details first
UName = myRS("Username")
LocURL = myRS("LocationURL")
' Get rid of the "Online User"
oConn.Execute ("DELETE FROM online WHERE ConIndex='" & ConIndex & "'")
' And now get who was in the room, and who we need to notify of the leaving
Set myRS2 = oConn.Execute("SELECT ConIndex FROM online WHERE LocationURL='" & LocURL & "'")
Do Until myRS2.EOF
' And now tell the people S/he has left the room
frmServerWindow.ServerSocket(myRS2("ConIndex")).SendData (" ## -cmdRoomLeave :$: " & UName)
myRS2.MoveNext
Loop
' Since there may not have been anyone in the room, there would have been an error
' So i made the "Closing up" A "Sub-Routine"
GoTo CloseUp:
Exit Sub
ErrorSub:
If Err.Number = "3021" Then
' No users where in the same room has the user
' So no need to do anything more then clean up
Else
Call frmServerWindow.ErrorSub(Err.Description, Err.Number)
Err.Clear
End If
' Clean up the Database Connections
GoTo CloseUp:
Exit Sub
CloseUp:
' Get rid of all those extra database connections,
' And delete the "Stuff" from the Memory
myRS.Close
myRS2.Close
oConn.Close
Set myRS = Nothing
Set myRS2 = Nothing
Set oConn = Nothing
End Sub
Perticularly the "CloseUp:" Sub...
Will this make other things caled "myRS, myRS2, and oConn" for different LogOffs, Errased, or just THIS sections?
(What i mean clearer, Will it DELETE both oConns, if the sub is called twice at the same time, and even if the Second "LogOff" is in the middle of a process?
Or is it "Process Independant"?
Tnx :)