Chapter 4. SQLite
Substituting text files for a database is like cutting a fish with a hammer. You might get it to work, but it’s going to be a really messy process. When your application needs a server-side storage mechanism but you can’t rely upon the presence of a specific database, turn to SQLite. It correctly handles locking and concurrent accesses, the two big headaches with home-brewed flat files.
Since the SQLite database is bundled with PHP 5, now every PHP 5 script can read, write, and search data using SQL. SQLite differs from most databases because it is not a separate application. Instead, SQLite is an extension that reads from and writes to regular files on the hard drive. Any PHP users who have permission to manipulate files can use SQLite to edit a database, just like they can use GD to edit images.
Although the name SQLite hints at a less than full-featured product,
SQLite actually supports almost all of SQL92, the SQL standard
specification. Besides the usual INSERTs and
SELECTs, with SQLite you can also use
transactions, query using subselects, define your own functions, and
invoke triggers.
SQLite actually performs most actions more quickly than many other
popular databases. In particular, SQLite excels at
SELECTing data.
If your application does an initial (or
periodic) data INSERT and then reads many times
from the database, SQLite is an excellent choice. The PHP web site
uses SQLite to handle some forms of searches.
Unfortunately, SQLite has some downsides. Specifically, ...
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.
Read now
Unlock full access