Android Question Connect a B4a app to a Mysql db on the network!

WebQuest

Active Member
Licensed User
Hi I'm testing for a future app that is connected to a db on the net. I'm trying Mysql's free hosting. I registered and with the phpAdmin I created the db on the server, through a module of implementation the connection. I'm using a MySql library.
I launch the debug app and the connection is established, but when I try to launch a Relase, the connection does not establish itself. Is there a need for a php web service? do I have to enable some permissions? Could someone enlighten me? Thanks in advance.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
    Connessione.ConnessioneVar
End Sub


'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim MyHandler As MysqlHandler
Dim Result As ResultSet
End Sub

Sub ConnessioneVar
    MyHandler.Initialize("xxxxxxxxx.net","xxxxxxxxx","xxxxxxxx","xxxxxxx")
  
    If MyHandler.isConnected=False Then
        Msgbox("Errore di conessione","Info")
        Return
        Else
            Msgbox("Connessione Stabilita"& CRLF&"Connesso al Server online"&CRLF&"Database Pronto!","Info")
            Return
    End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
I'm trying Mysql's free hosting
i guess you are not allowed to connect to the Database from outside the Server machine.

Get a Hosting where you are allowed to connect to the DB from other IPs than 127.0.0.1
Or setup a PHP-Script as middleware on the same server.

I suggest to use a cheap VPS and setup MySQL and jRDC2 on this machine.
 
Upvote 0

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hello

I do not know of any free hosting service that supports remote connections to mysql, the majority that works are paid hosting services.

The problem that you are sure of is that your free hosting service does not support remote connections, to prove it use HeidiSQL: https://www.heidisql.com/
 
Upvote 0

WebQuest

Active Member
Licensed User
I tried with Apache to connect to a service in php that requires connection in localhost .. but also here is neither debugging nor relase. where am I wrong?
B4X:
'Activity module
Sub Process_Globals
    
End Sub

Sub Globals
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    LoadDbList 
End Sub
Sub LoadDbList
  
    ExecuteRemoteQuery("SELECT Nome,Tipologia,Citta,Strada,Tel,ID FROM Fornitori ","r1" )

End Sub

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://localhost/ServiceApp.php", Query)
End Sub

Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
    
        Select Job.JobName
            
            
            Case "r1"
            Msgbox("Connessione effettuata","info")
           Case "r2"
                
        End Select
    Else
        Log(Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0

WebQuest

Active Member
Licensed User
Thanks for your suggestions. But I'm testing a direct connection by initializing (Handler) with Host [Port], Dbname, UserName, Pass. in debugging the connection works, and I can read the db data by displaying them in my app. with this code:
B4X:
Sub Loadlist
    Connessione.ConnessioneVar
    ListView1.Clear
    Connessione.Result = Connessione.MyHandler.Query("SELECT Nome FROM Fornitori")
   
    For i =0 To Connessione.Result.RowCount -1
        Connessione.Result.Position=i
        ListView1.AddSingleLine(Connessione.Result.GetString2("Nome"))
        Log(Connessione.Result.GetString2("Nome"))
    Next
    Connessione.MyHandler.Close
End Sub


Now I'm trying to add a record to the db via app without success, it does not return any error but the record is not added to the db. Maybe it's a problem of writing privileges?
B4X:
Sub BtInsert_Click
   
    Connessione.ConnessioneVar
    Connessione.MyHandler.Exec("INSERT INTO Fornitori (Nome) VALUES ('" & EditTextNome.Text & "')")
    Connessione.MyHandler.Close
    Loadlist
   
End Sub
 
Last edited:
Upvote 0
Top