Posts Tagged ‘Mysql in visual basic Sample Source Code’


Mysql in visual basic Sample Source Code

This item was filled under [ FREE SOURCE CODE, Visual Basic 6.0 ]
  1. 'Here I create a variable named MySQL as a new connection object for MySQL
  2. Global MySQL As New MySQL_CONNECTION
  3.  
  4. Private Function MySQL_Connect() As Boolean
  5. Dim res_MySQL As MYSQL_CONNECTION_STATE
  6.  
  7. MySQL_Connect = False
  8. res_MySQL = MySQL.OpenConnection("server", "username", "password", "database", 3306, CLIENT_COMPRESS)
  9.  
  10. If res_MySQL = MY_CONN_OPEN Then
  11. MySQL_Connect = True
  12. End Function
  13.  
  14. ' Query -> MySQL query to execute.
  15. ' CloseRS -> Optional. Close recordset created after executing Query.
  16. ' RS -> Optional. Reference to externaly created variable, declared as MYSQL_RS. If not closed, it will be available to the program after the query is executed.
  17. ' lAffected -> Optional. Numer of rows affected after te Query.
  18. Public Sub SQLQuery(ByVal Query As String, Optional ByVal CloseRS As Boolean = False, Optional ByRef RS As MYSQL_RS, Optional ByRef lAffected As Long)
  19. Dim ERR As MYSQL_ERR
  20.  
  21. Set RS = MySQL.Execute(Query, lAffected)
  22. Set ERR = MySQL.Error
  23.  
  24. If ERR.Number <> 0 Then
  25. ' Handle any eventual errors that occurred during MySQL query
  26. End If
  27. ERR.Clear
  28. Set ERR = Nothing
  29.  
  30. If CloseRS Then
  31. RS.CloseRecordset
  32. Set RS = Nothing
  33. End If
  34. End Sub
  35. Continue reading...