PHP 7 interview question · Most asked
Compare PDO and mysqli.
Summary
PDO is a database-agnostic abstraction supporting a dozen drivers with named placeholders; mysqli is MySQL-specific with access to MySQL-only features. Both support prepared statements.
Longer Answer
PDO: named parameters (:id), a consistent API across databases, flexible fetch modes (FETCH_CLASS), and exceptions via ERRMODE_EXCEPTION (the default since PHP 8.0). mysqli: positional ? only, procedural and OO APIs, async queries and multi-statements. Most modern projects use PDO (directly or through an ORM).
Key Points
- PDO: multi-DB, named params
- mysqli: MySQL-only features
- Both support prepared statements
- Exceptions mode recommended
Comparison / Tradeoffs
| PDO | mysqli | |
|---|---|---|
| Databases | 12+ drivers | MySQL/MariaDB |
| Placeholders | Named and positional | Positional |
| API | OO | OO + procedural |
More most-asked PHP 7 questions
- What are typed properties in PHP 7.4?
- How do return type declarations work in PHP 7?
- What were the headline improvements of PHP 7.0 over PHP 5.6?
- Explain scalar type declarations and coercive vs strict mode in PHP 7.
- Explain the `Throwable`, `Error` and `Exception` hierarchy introduced in PHP 7.
- What are nullable types in PHP 7.1?
- What does the null coalescing operator `??` do, and how is it different from `isset()` with a ternary?
- What are arrow functions in PHP 7.4 and how do they differ from closures?