Databases for PHPs
Databases in PHP are accessed mainly through PDO, a uniform interface for MySQL, PostgreSQL, SQLite and others. Prepared statements send SQL and values separately, which blocks injection. ORMs such as Eloquent or Doctrine map rows to objects, trading some control for faster development.
Stage: Web and Data · Part of the PHP roadmap · Last reviewed 19 November 2026
What to learn in Databases
- Open a PDO connection with error mode set to exceptions
- Run a prepared statement with bound parameters
- Fetch rows as associative arrays or objects
- Wrap related queries in a transaction with commit and rollback
- Map a table to a model class using an ORM
Databases interview questions
Why do prepared statements stop SQL injection?
The SQL text with placeholders is compiled first, and user values are sent separately as data. The database never interprets a value as SQL syntax, so input like ' OR 1=1 cannot change the query structure.
What is the N+1 query problem in an ORM?
It occurs when code loads a list with one query and then runs one extra query per item to get a relation, producing N+1 queries. Eager loading with a join or a second batched query fixes it.
Where Databases fits in the PHP roadmap
Databases belongs to the Web and Data stage (beginner level), which takes about 19 hours. Build applications.