B4J Question [SithasoDaisy5] demo & SQLite

Gianni M

Well-Known Member
Licensed User
Longtime User
@Mashiane
hi,
i try your SithasoDaisy5Demo, module bas "pgPHPSQLite", database "northwind.sqlite" and table "Customers".
database exists into folder "C:\laragon\www\sd5demo\assets\" and table "Customers" contains 29 rows, but demo not show nothing.

Do I need to configure something in the "Main" module, or in the "api.php" file?
 

Mashiane

Expert
Licensed User
Longtime User
Hi

Just to be clear, are you talking about the demo deployed on Vercel? If so, yes that will not work as vercel has no php installed.

Locally it should work if you have php with the sqlite drivers installed. The demo locally is deployed on laragon with sqlite3 and sqlite pdo extension activated.

1754293958708.png


With that said. The env.json file in the demo keeps the settings for the app.

B4X:
{
    "api-key": "jNOEqK8xvAqWWRf7B4jlw2ppOCeBoHunex4ViA1txPrG7V9DW1dG737HhseS4E5Ca3xVaUtUwbDRIOrkwEZv7SEvUQP6jClRpDESkRUnshgyngNDd2epbJWjF48xAzKp",
    "api-url": "http://127.0.0.1/sd5demo",
    "host": "../assets/northwind.sqlite",
    "driver": "sqlite", 
    "user": "",
    "password": "",
    "port": "3306",
    "dbname": ""
}

This is read when the app starts and these settings are passed to api.php by the SDUIMySQLREST class.

APP LAUNCH

B4X:
Sub BANano_Ready
'    'get the environment variables
    'get the env.json content
    Dim env As Map = BANano.Await(BANano.GetFileAsJSON("./assets/env.json?" & DateTime.Now, Null))
    'get the api key
    APIKey = env.Get("api-key")
    'get the path to the URL
    ServerURL = env.Get("api-url")
    '
    DBHost = env.Get("host")
    DBDriver = env.Get("driver")
    DBUser = env.Get("user")
    DBPassword = env.Get("password")
    DBPort = env.Get("port")
    DBName = env.Get("dbname")
    '
    pgIndex.Initialize
End Sub

APP USAGE

See the Show method

WHAT HAPPENED?

I updated the api.php file to make it dynamic so that its able to use connection parameters dynamically. These are specified as header settings.

B4X:
// --- Dynamic DB Configuration via Headers ---
    $headers = getallheaders();
    $host = $headers['X-Host'] ?? '';
    $user = $headers['X-User'] ?? '';
    $password = $headers['X-Password'] ?? '';
    $dbname = $headers['X-DBName'] ?? '';
    $driver = $headers['X-Driver'] ?? 'mysql';
    $port = $headers['X-Port'] ?? '';
    $config = new Config([
        'driver' => $driver,
        'address' => $host,
        'port' => $port,
        'username' => $user,
        'password' => $password,
        'database' => $dbname,
        'debug' => true,
        'tables' => 'all',
        'controllers' => 'records,columns,tables,openapi,status',
        'middlewares' => 'apiKeyAuth,sanitation',
        'apiKeyAuth.keys' => 'jNOEqK8xvAqWWRf7B4jlw2ppOCeBoHunex4ViA1txPrG7V9DW1dG737HhseS4E5Ca3xVaUtUwbDRIOrkwEZv7SEvUQP6jClRpDESkRUnshgyngNDd2epbJWjF48xAzKp',
        'apiKeyAuth.header' => 'X-API-Key',
    ]);

If there is anything else, please dont hesitate to indicate, thanks.
 
Upvote 0

Gianni M

Well-Known Member
Licensed User
Longtime User
wow, solved!
on demo locally

actived sqlite3 and sqlite pdo extension

thanks to you my friend
 
Upvote 0
Top