MySQL taught the SQL; this section is the PHP side of it. PDO (PHP Data Objects, since PHP 5.1) opens the connection, sends statements, passes values in safely and turns rows into arrays or objects, with one API for MySQL 524 , PostgreSQL 1,289 , SQLite 4,756 and the other drivers. Every example runs on PHP 8.5 against the shop database of MySQL, logged in as shop_app, the least-privilege account of Subsection 3.16.9.
Subsections
- PDO, mysqli and Why PDO Wins
- Connecting with PDO
- Error Modes and Exceptions
- query, exec, prepare
- Placeholders
- Emulated vs Native
- Binding
- Placeholder Limits
- Fetch Modes
- Inserts and IDs
- Transactions
- Special Column Types
- Character Sets
- Pdo\Mysql
- A Repository Class for a Table
- Connection Handling
- Query Builders and ORMs