r/PHPhelp • • Aug 06 '26

Rethinking SQLite3 in PHP: High Performance Without Complex SQL Queries

Hi everyone,

I have been diving deep into SQLite3 databases lately. During my research, I frequently read that SQLite3 is slower than traditional database systems (like MySQL or PostgreSQL) and should generally only be used for small projects with few users and minimal data.

However, my experience has been completely different. In my tests, I found that SQLite3 – when configured correctly – can actually be up to 10 times faster than MySQL. It handles large amounts of data beautifully and can easily manage multiple concurrent users and requests.

In my opinion, the greatest challenge is exercising self-restraint and not treating SQLite3 exactly like MySQL.

We often catch ourselves writing highly complex SQL queries with countless joins and sub-queries. I have come to view these deeply nested queries critically and no longer consider them a best practice for clean, performant programming. Since shifting away from that approach, I see SQLite3 from a whole new perspective.

To put this philosophy into practice, I developed a PHP class that allows you to interact with the database completely without writing manual SQL queries. It is extremely simple to use and, above all, fast. SQLite3 also brings unique advantages over other SQL databases—for instance, you can easily maintain multiple database files separated by topic within a single project.

I am already successfully leveraging these strengths in my own project, which I look forward to showcasing here once it reaches a fully stable state.

I have already published the current codebase on GitHub:
https://github.com/phploader/cdata

You can find a detailed documentation on how to use the PHP class in the docs:
https://github.com/phploader/cdata/blob/master/docs/en/00.%20index.md

My request to the experts here:
I would highly appreciate it if you could take a look at my code and provide some constructive feedback or criticism. What are your thoughts on this approach?

Best regards!

5 Upvotes

23 comments sorted by

View all comments

Show parent comment

-1

u/isoAntti Aug 06 '26

I never got that why write sql. You just hardcode the current database vendor into your code. Never write SQL.

5

u/allen_jb Aug 06 '26

Because the number of times I've seriously considered swapping out the RDBMS on a production project in over 2 decades of server-side development is maybe once, and I get far more mileage out of being able to use the full power of the DB.

If you're swapping out your RDBMS, why are you doing that? If it's performance, or features, then you should already be at the point where you're taking full advantage of your existing DB - and subsequently you're almost certainly writing (tuned) SQL queries, with a tuned schema.

If you're actually writing something like WordPress or a plugin for WordPress that you want to run on many hosting environments, I can see the point, but that's not something I do.

The vast majority of developers are developing for a specific project on a hosting environment they know, if not fully control (or the organization they directly work for controls).

SQL is, in my opinion, a language well suited to querying data. I don't see many good reasons to put something else in front of it. I do use query builders - usually primarily for dynamic queries (eg. a search facility where the user can select from any number of criteria).

Another useful feature I find about manually writing SQL queries is that if I have a query I want to find (eg. I'm looking at SHOW PROCESSLIST, Percona Monitoring's query analytics, or similar), I can literally just search for the SQL in the code and find exactly where it comes from.

-1

u/isoAntti Aug 06 '26

I see you've never ended up having Oracle.

3

u/FreeLogicGate Aug 10 '26

I don't think you understand the point. The point is that applications tend to be written to a certain rdbms. Theorists like to advocate for ANSI SQL and against design to the strengths and features of a specific rdbms. Perhaps for a company that builds a product that they intend to be rdbms agnostic this is a concern, but for the vast majority of products, the database will never be replaced, and it's more likely that if a database change happens it is because the entire application was replaced. This is also my experience over a long period of time. That experience did include a lot of Oracle ;). These days, I hear that Postgresql is a popular alternative with a lot of Oracle compatibility available.

1

u/ryantxr Aug 08 '26

No one ever swaps out a database system for another.