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

Discussion in 'B4J Questions' started by Mashiane, Jan 20, 2019.

  1. Mashiane

    Mashiane Expert Licensed 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: Apr 8, 2019
    joulongleu likes this.
  2. Kiffi

    Kiffi Active Member Licensed User

    Here is a very simple code to show how to communicate with the server via BANano Inline-PHP:

    Code:
    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
     
    Mashiane, Harris and alwaysbusy like this.
  3. alwaysbusy

    alwaysbusy Expert Licensed User

    Ajax or inline php can do the job.
     
    Last edited: Jan 20, 2019
    joulongleu and Mashiane like this.
  4. alwaysbusy

    alwaysbusy Expert Licensed User

    joulongleu likes this.
  5. Mashiane

    Mashiane Expert Licensed User

    Great stuff thanks a lot. I like the way you simplified the code example.

    I will play around.

    #somuchtolearn
     
    joulongleu likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice