B4J Question [BANano]: [SOLVED] Using MySQL / MSSQL with PHP

Mashiane

Expert
Licensed User
Longtime User
Hi there

Update: April 8, 2019 Solution

[BANAno] MySQL CRUD with PHP - Part 1
[BANano] MySQL CRUD with PHP - Part 2

I have an issue that I need to address. I have a backend that I need to speak to from my BANano App, this could either be MySQL or either MSSQL (no decision as yet). I guess with PHP this could happen well, this will basically be for CRUD functionality.

What advise can you push my way on such? (if any)

Thanks.
 
Last edited:

Kiffi

Well-Known Member
Licensed User
Longtime User
Here is a very simple code to show how to communicate with the server via BANano Inline-PHP:

B4X:
Sub Process_Globals
   
    Dim BANano As BANano 'ignore
   
End Sub

Sub AppStart (Form1 As Form, Args() As String)

    BANano.Initialize("InlinePhpTest", "InlinePhpTest", 1)
   
    BANano.UseServiceWorker = False
   
    BANano.HTML_NAME = "index.html"
   
    BANano.Header.Title = "InlinePhpTest"
   
    BANano.Header.AddCSSFile("https://cdnjs.cloudflare.com/ajax/libs/mini.css/3.0.1/mini-default.min.css")
   
    BANano.PHP_NAME = "GetData.php"
   
    BANano.PHPHost = "http://localhost/BANano/InlinePhpTest/"
   
    BANano.PHPAddHeader("Access-Control-Allow-Origin: *")
   
    BANano.Build("C:\inetpub\wwwroot\BANano\") ' Customize to your needs!
   
    ExitApplication

End Sub

#If PHP

    function Login($Username, $Password) {
        if ($Username=="John" && $Password=="Doe") {
            echo "OK";
        } else {
            echo "KO";
        }
    }

#End If

Sub InlinePhpTest_Ready()

    BuildInput("txtUsername", "text", "Username:", "John")
    BuildInput("txtPassword", "password", "Password:", "Doe")
    BuildButton("btnLogin", "Login")
   
    BANano.GetElement("body").Append("<br />")

End Sub

public Sub btnLogin_Click(event As BANanoEvent)
   
    If BANano.CheckInternetConnectionWait Then

        Dim Username As String = BANano.GetElement("#txtusername").GetValue
        Dim Password As String = BANano.GetElement("#txtpassword").GetValue
       
        Dim Result As String = BANano.CallInlinePHPWait("Login", CreateMap("Username":Username, "Password":Password))
       
        Select Result
            Case "OK"
                AddOutput("Login: OK :-)")
            Case Else
                AddOutput("Login failed!")
        End Select
       
    Else
       
        AddOutput("You are not connected to the internet!")
       
    End If

End Sub

Sub BuildInput(ID As String, InputType As String, LabelText As String, Value As String)
   
    ID = ID.ToLowerCase
    BANano.GetElement("body").Append($"<label for="${ID}">${LabelText}</label>"$)
    BANano.GetElement("body").Append($"<input type="${InputType}" id="${ID}" value="${Value}">"$)
   
End Sub

Sub BuildButton(ID As String, Text As String)
   
    ID = ID.ToLowerCase
   
    Dim Button As BANanoElement = BANano.GetElement("body").Append($"<button id="${ID}">${Text}</button>"$).Get($"#${ID}"$)
   
    Button.On("click", Me, ID & "_click")
   
End Sub

Sub AddOutput(Message As String)
   
    BANano.GetElement("body").Append($"<p>${Message}</p>"$)
   
End Sub

Greetings ... Peter
 
Upvote 0
Top