B4J Library [SithasoDaisy] Plug n Play PHP CRUD REST API (MySQL, SQLite, MSServer, PostGreSQL) for BANano

Hi

Plug n Play? Yep...

1. Add the api.php file to your assets. Get it from this GitHub repo

I spoke about this in 2022 on the BVAD3 library.


2. Change the connection parameters in the api.php file.

1688823488498.png


Save the file and click 'Sync' in the IDE. You are good to go.

Example: We have a categories table in our db named bvad3products with column 'id' auto-increment.

1688824001906.png



Lets do some crud...
 

Attachments

Last edited:
Create records

We initialize the class first! sdmysqlapi below is our sub-domain where our app is hosted on

Code: Copy
Dim mysqlapi As SDUIMySQLAPI
    mysqlapi.Initialize(Me, "mysqlapi", "https://localhost/sdmysqlapi/assets/api.php", "categories")
    mysqlapi.ShowLog = False
    mysqlapi.SchemaAddInt(Array("id"))
    mysqlapi.SchemaAddText(Array("name","color"))
    mysqlapi.PrimaryKey = "id"
    mysqlapi.AutoIncrement = "id"

Code: Copy
mysqlapi.PrepareRecord
    mysqlapi.SetField("name", "Anele Mbanga " & SDUIShared.DateNow)
    Dim id As String = BANano.Await(mysqlapi.CREATE)
    Log(id)

Code: Copy
    mysqlapi.PrepareRecord
    mysqlapi.SetField("id", 23)
    mysqlapi.SetField("name", "Cars " & SDUIShared.DateNow)
    Dim id As String = BANano.Await(mysqlapi.CREATE_OR_UPDATE)
    Log(mysqlapi.RowCount)
    Log(id)

You can also pass a map variable with

Code: Copy
mysqlapi.SetRecord(MapName)
 
Last edited:
Update records

Code: Copy
mysqlapi.PrepareRecord
    mysqlapi.SetField("id", 67)
    mysqlapi.SetField("name", "Shandukani " & SDUIShared.DateNow)
    BANano.Await(mysqlapi.UPDATE)
    Log(mysqlapi.RowCount)

Code: Copy
mysqlapi.PrepareRecord
    mysqlapi.SetField("color", "green")
    BANano.Await(mysqlapi.UPDATE_BY("name", "Shandukani " & SDUIShared.DateNow))
 
Last edited:
Read records

Code: Copy
Dim found As Map = BANano.Await(mysqlapi.READ(97))
    Log(found)

Code: Copy
    Dim found As Map = BANano.Await(mysqlapi.READ_BY("name", "Shandukani " & SDUIShared.DateNow))
    Log(found)

Code: Copy
mysqlapi.CLEAR_WHERE
    mysqlapi.ADD_WHERE("name", mysqlapi.OPERATOR_EQ, $"Cars ${SDUIShared.DateNow}"$)
    BANano.await(mysqlapi.SELECT_WHERE)
    Log(mysqlapi.result)


Code: Copy
mysqlapi.CLEAR_WHERE
    mysqlapi.ADD_ORDER_BY("name")
    BANano.await(mysqlapi.SELECT_ALL)
    Do While mysqlapi.NextRow
        Dim rec As Map = mysqlapi.Record
        'Log(rec)
    Loop

Code: Copy
mysqlapi.CLEAR_WHERE
mysqlapi.ADD_ORDER_BY_DESC("name")
    BANano.await(mysqlapi.SELECT_ALL)
    Do While mysqlapi.NextRow
        Dim rec As Map = mysqlapi.Record
        Log(rec)
    Loop
 
Last edited:
Interesting reading...



 
I can't describe how helpfull was this one using sithasodaisy.

Can we add an authentication in order to make our calls safe. Because anyone who has the api link (https://localhost/sithasomultiuser/assets/api.php/records/posts/1) can get data.

I see at first post that there is SDUIFetch module, where there is Basic authentication method but i am not sure how to use it...

At github info page there are five types of authentication supported (API key, API key DB, Database, Basic, JWT). Can we have them?
 
SDUIFetch
This is just a wrapper to make using BANanoFetch easier to use and nothing else.

Can we add an authentication in order to make our calls safe
I am not a PHP expert sadly and I would also love to have such things working. Perhaps if someone could figure it out it would help.

Do you have any ideas perhaps? I had shared this in the forum because it was so easy plug and play.
 
I can't describe how helpfull was this one using sithasodaisy.

Can we add an authentication in order to make our calls safe. Because anyone who has the api link (https://localhost/sithasomultiuser/assets/api.php/records/posts/1) can get data.

I see at first post that there is SDUIFetch module, where there is Basic authentication method but i am not sure how to use it...

At github info page there are five types of authentication supported (API key, API key DB, Database, Basic, JWT). Can we have them?
Hi...

Check this out...

 
Docs

 
Back
Top