SQLite - no database server
The application database is MySQL by default. One setting makes it SQLite: a single file, no server to install, which is all a small application or a test needs.
# apps/myapp/.env - read with padEnv, as every database setting is
padSqlDriver=sqlite
padSqlDatabase=myapp/myapp.sqlite # under DATA/
padSqlSetup=_install/schema.sql # builds it the first time
$padSqlDatabase is the file - a relative name lives under DATA/. $padSqlSetup is optional: a .sql file in the application that is run once, when the database file does not exist yet, so the first request builds the database from text kept with the application.
Nothing else changes. The page below is one of the database examples, which this manual runs on MySQL - with the settings above it runs unchanged on SQLite:
|
PHP fragments/database_1.php |
HTML fragments/database_1.pad |
Result |
|---|---|---|
|
|
Jim's phone number is 555-4364 |
- The
db()verbs answer in the same shapes -field,record,array,check,insertwith the new id,updateanddeletewith the rows they touched. - The
{0}placeholders escape the way SQLite needs: a quote is doubled, so a value never ends its literal early. - The database tags, named
_data/*.sqlqueries and the Select subsystem work as they do on MySQL. - The SQL is SQLite's own:
||joins strings, a key isinteger PRIMARY KEY AUTOINCREMENT.