Documentation · Chapter 07

Keep data
after the request.

A session can remember a few values, but a real application needs durable, organized, searchable storage.

We replace reading-list's temporary storage with SQLite without changing the application's purpose.

≈ 90 min

So far, our library had a short memory.

Books lived in the browser session. Another visitor did not see the same list, and an expired session could erase everything. A database keeps records independently from a page or visitor.

A database resembles a well-run library

Table

A catalog devoted to one kind of thing, here books.

Row

One specific book stored in the catalog.

Column

A shared piece of information: title, author, date.

Primary key

The unique identifier distinguishing two books.

A data journey

phpaml — zsh
Form → Controller → Book entity → DbContext → SQLite
SQLite → DbSet<Book> → Controller → View

PHPAML Data does not replace the database: it translates between PHP objects and storage. This layer is called an ORM, for Object-Relational Mapping.

VOCABULARY

Words to remember

PersistenceKeeping data after a request ends.
SchemaStructure of tables and columns.
EntityPHP object representing a record.
MigrationVersioned schema change.

SUMMARY

What to remember

  • A session belongs to a visit; a database belongs to the app.
  • A table holds rows structured into columns.
  • PHPAML Data connects PHP objects to storage.
  • A migration evolves structure reproducibly.