Complex operations and patterns for advanced use cases.
Managing multiple database connections and switching between them.
Topics covered:
- Creating connections without default connection
- Adding multiple named connections
- Switching between connections with
connection() - Managing connections to different database types
- Connection reuse and cleanup
- Multi-database applications
Bulk inserts and data loading from files.
Topics covered:
- Bulk inserts with
insertMulti() - Loading data from CSV files with
loadFromCsv() - Loading data from XML files with
loadFromXml() - Batch size configuration
- Performance optimization for large datasets
- Error handling in bulk operations
Note: For JSON loading, see 05-file-loading/.
INSERT or UPDATE operations (UPSERT).
Topics covered:
- MySQL REPLACE operations
- INSERT ON DUPLICATE KEY UPDATE (MySQL)
- INSERT ON CONFLICT (PostgreSQL)
- INSERT OR REPLACE (SQLite)
- Dialect-specific upsert strategies
- Handling unique constraints
- Batch upserts
Subqueries in SELECT, WHERE, and FROM clauses.
Topics covered:
- Scalar subqueries in SELECT
- Subqueries in WHERE conditions
- EXISTS and NOT EXISTS
- Subqueries with IN operator
- Subqueries in FROM clause (derived tables)
- Correlated subqueries
- Multiple subqueries in one query
- QueryBuilder subquery support
php 01-connection-pooling.phpPDODB_DRIVER=mysql php 01-connection-pooling.phpPDODB_DRIVER=pgsql php 01-connection-pooling.php- Connection pooling reduces overhead in multi-database applications
- Bulk operations are significantly faster than individual inserts
- Upserts reduce the need for SELECT-then-INSERT/UPDATE patterns
- Subqueries can sometimes be replaced with JOINs for better performance
Explore more advanced topics:
- Batch Processing - Generator-based processing for large datasets
- Exception Handling - Robust error handling patterns
- Connection Retry - Automatic retry logic