What is the difference between PDO and MySQLi?
Why Interviewers Ask This
This tests whether you can apply PHP knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
Both are PHP extensions for database interaction, but they differ in scope and philosophy. PDO (PHP Data Objects) is a database abstraction layer supporting 12+ database drivers — switching from MySQL to PostgreSQL requires only changing the DSN connection string. It uses a unified API regardless of the underlying database. MySQLi (MySQL Improved) is MySQL-specific but provides both an object-oriented and a procedural interface. MySQLi supports all MySQL-specific features (async queries, multi-statements) that PDO might not expose. Both support prepared statements and transactions. The recommendation is always use PDO for new projects — the database portability it provides is invaluable, and its API is cleaner for building abstractions on top of. Use MySQLi only if you need MySQL-specific features PDO does not expose.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex PHP answers easy to follow.
Previous
What is declare(strict_types=1) in PHP?
Next
What is a Service Container (IoC Container) in PHP?