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

Ola

UPDATE: BANanoSQLite now available for actual sqlite db file CRUD functionality.

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

B4X:
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

B4X:
extension=pdo_sqlite

So the code to create the database is...

B4X:
' 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.
 

Attachments

  • BANanoSQLiteCode.zip
    1.2 KB · Views: 439
Last edited:
Top