VB6 用ADO连接mysql
Public Function MysqlDataOpen(ByVal gcnmysql1 As ADODB.Connection, ByVal server As String, ByVal port As String, ByVal username As String, ByVal pwd As String, ByVal database As String) As Boolean
On Error Resume Next
DoEvents
With gcnmysql1
.Provider = "MSDASQL"
If .State = adStateOpen Then
.Close
End If
MsgBox .State
.ConnectionString = "driver={mysql odbc 5.1 driver};server=" & server & ";port=" & port & ";uid=" & username & ";pwd=" & pwd & ";database=" & database & ";OPTION=3"
.Open
If Err <> 0 Then
MsgBox "连接失败!(请确保用户名与密码输入无误)", vbInformation, "数据库连接"
MsgBox Err.Description
Exit Function
End If
End With
MysqlDataOpen = True
End Function