B4J Tutorial [BANano] Exploring Using PHP & SQLite for your WebApp

Discussion in 'B4J Tutorials' started by Mashiane, Mar 10, 2019.

Tags:
  1. Mashiane

    Mashiane Expert Licensed User

    Ola

    This is part 1 of a series of my explorations using SQLite as a backend to a BANano app. I need a way to persist the data to a database, but thought of a serverless database for now.

    Series

    1. Create the SQLite database using Php (i.e inline php)
    2. Create tables
    3. Insert records
    4. Update records
    5. Delete records

    Ok. First things first, I came across this youtube. Me thinks this possible. Me try do this with BANano.

    1. Create the SQLite database using Php.

    I am using Xamp for my webserver but any would do. Edit your php.ini and uncomment this line

    Code:
    extension=sqlite3
    by removing the ; infront of it. With xamp this is easy as clicking config and then selecting php.ini opening the default editor and then changing the content [for this line]

    I found the following line also uncommented, anyway

    Code:
    extension=pdo_sqlite
    So the code to create the database is...

    Code:
    ' HERE STARTS YOUR APP
    Sub BANano_Ready()
        
    Dim res As String = BANano.CallInlinePHPWait("openSQLite", CreateMap("Name"$"${AppName}.db"$))
        
    Log(res)
    End Sub

    #if PHP
       $db;
       function openSQLite($Name) {
           $db = new SQLite3($Name);
           if(!$db) {
          echo $db->lastErrorMsg();
       } else {
          echo "Opened database successfully\n";
       }
    }
    #End If
    Where the AppName is the name of your database e.g. mashy.

    Attached is the source code to create the db. It echos the result on the console as I dont have any controls in my page.

    Next inline will be table creation.
     

    Attached Files:

    aidymp, amaxco and joulongleu like 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