Article
PHP Database Modernization Guide
Move legacy PHP data access from mysql_* to mysqli/PDO with prepared statements, utf8mb4, transactions, and credentials kept outside the webroot.
Database modernization removes the obsolete mysql_* extension, stops string-built queries, and aligns connection charset and SQL modes with what modern MySQL/MariaDB expect. Do this in vertical slices (login, checkout, admin) rather than a single unreviewed rewrite of every query.
LEGACY — mysql_*
MODERN — PDO
PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
$stmt = $pdo->prepare('SELECT id, total FROM orders WHERE user_id = ?');
$stmt->execute([(int) $userId]);
Workstream checklist
- Prepared statements for every user-influenced query
- utf8mb4 on connection, tables, and columns
- Strict SQL modes on staging before production
- Transactions around multi-step writes
- Foreign keys and index review where data allows
- Schema changes via migrations with backups—not ad-hoc production phpMyAdmin clicks
- Credentials outside the document root / in environment variables
Connection failures belong in logs with DSN host/dbname—not passwords. Related security notes live in PHP security modernization. PDO manual: php.net/pdo.
Related reading
- Composer Modernization Center Add Composer to legacy PHP projects, migrate includes to autoloading, set platform constraints, and replace a…
- PHP 5 to Modern PHP: Complete Incremental Migration Guide A deep, production-minded path from PHP 5.x codebases to supported PHP 8.x: removed extensions, charset, PDO,…
- PHP Security Modernization for Legacy Applications Upgrade inherited PHP security practices: prepared statements, password hashing, sessions, CSRF, XSS escaping…
- PHP 7 to PHP 8 Migration Guide Deep guide to PHP 8.0 breaking changes that matter for PHP 7 applications, with upgrade tactics through suppo…
- Inheriting a Legacy PHP Application A first-30-days playbook for developers handed an unfamiliar PHP codebase: runtime truth, risk triage, and sa…