Skip to Main Content
PHP Cookbook
book

PHP Cookbook

by Eric A. Mann
May 2023
Intermediate to advanced content levelIntermediate to advanced
431 pages
8h 55m
English
O'Reilly Media, Inc.
Content preview from PHP Cookbook

Chapter 16. Databases

Modern software applications, particularly on the web, use state in order to function. State is a way to represent the current condition of the application for a specific request—who is logged in, what page they’re on, any preferences they’ve configured.

Typically, code is written to be more or less stateless. It will function the same way regardless of the state of the user’s session (which is what makes system behavior predictable within an application for multiple users). When a web application is deployed, it’s done so again in a stateless manner.

But state is vital for keeping track of user activity and evolving the way the application behaves for the user as they continue to interact with it. In order for an otherwise stateless piece of code to be aware of state, it must retrieve that state from somewhere.

Typically, this is done through the use of a database. Databases are efficient ways to store structured data. There are generally four kinds of databases you will work with in PHP: relational databases, key-value stores, graph databases, and document databases.

16.1 Relational Databases

A relational database breaks data down into objects and their relationships with one another. A particular entry—like a book—is represented as a row in a table, with columns containing data about books. These columns might include a title, ISBN, and subject. The key thing to remember about relational databases is that different data types reside in different tables. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Clean Code in PHP

Clean Code in PHP

Carsten Windler, Alexandre Daubois
Go Cookbook

Go Cookbook

Sau Sheong Chang

Publisher Resources

ISBN: 9781098121310Errata Page