« Good bye Phoenix! | Home | MBS Xojo Plugins, ver… »

MySQL with SSL in MBS Xojo SQL Plugin


Today an example on how to connect to MySQL via MBS SQL Plugin in Xojo:

dim con as new SQLConnectionMBS try // Specify SSL key file Dim keyFile As FolderItem #If TargetMacOS Then // pick from inside budnle keyFile = App.ExecutableFile.Parent.Parent.Child("Resources").Child("client-test-key.pem") #Else // pick next to exe file keyFile = GetFolderItem("client-test-key.pem") #EndIf con.Option("MYSQL_SSL_KEY") = keyFile.NativePath // Specify SSL certificate file Dim certFile As FolderItem #If TargetMacOS Then // pick from inside budnle certFile = App.ExecutableFile.Parent.Parent.Child("Resources").Child("client-test.pem") #Else // pick next to exe file certFile = GetFolderItem("client-test.pem") #EndIf con.Option("MYSQL_SSL_CERT") = certFile.NativePath // set where to find the MySQL client library #If TargetMacOS Then // pick from inside budnle con.SetFileOption con.kOptionLibraryMySQL, App.ExecutableFile.Parent.Child("libmysqlclient.18.dylib") #elseif TargetWin32 then // pick next to exe file con.SetFileOption con.kOptionLibraryMySQL, App.ExecutableFile.Parent.Child("libmysql.dll") #elseif TargetLinux then // pick next to exe file con.SetFileOption con.kOptionLibraryMySQL, App.ExecutableFile.Parent.Child("libmysql.so") #EndIf dim server as string = "myuser@mydb" dim DBLogin as string = "xxx" dim DBPassword as string = "xxx" con.Connect(server, DBLogin, DBPassword, SQLConnectionMBS.kMySQLClient) If Not con.Error Then MsgBox "We are connected!" Else MsgBox con.ErrorMessage End If catch r as RuntimeException MsgBox r.message end try

If the options MYSQL_SSL_KEY, MYSQL_SSL_CERT, MYSQL_SSL_CA, MYSQL_SSL_CAPATH or MYSQL_SSL_CIPHER are set, the plugin calls mysql_ssl_set function to pass those to MySQL client library.
31 07 17 - 20:36
one comment

Thank you for this example. Works like a charm.
Sascha (URL) - 31 07 17 - 21:09


  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.