Article

ZF1 Database Modernization: Zend_Db toward PDO and utf8mb4

Modernize ZF1 data access: adapters, prepared statements, charset upgrades, and gradual moves off brittle Zend_Db usage.

ZF1 data layers often mix Zend_Db_Table, ad-hoc Zend_Db_Adapter SQL, and leftover mysql_* calls in helpers. Modernization here is about correctness and security—not forcing Doctrine onto every legacy screen.

Inventory the real access patterns

  • Adapter type in application.ini (pdo_mysql, mysqli, etc.)
  • Table gateway models vs raw SQL in controllers
  • Charset/collation (utf8 vs utf8mb4)
  • Any direct mysql_* usage—pair with mysql_connect removed
// LEGACY — string-concat SQL risk
$db->query("SELECT * FROM users WHERE email = '" . $email . "'");
// MODERN — prepared statements (PDO or adapter support)
$stmt = $db->query(
    'SELECT * FROM users WHERE email = ?',
    [$email]
);

Practical upgrade sequence

  1. Standardize on PDO MySQL (or mysqli) with exceptions enabled in staging.
  2. Fix SQL injection hotspots before chasing ORM fashion.
  3. Migrate schemas/connections to utf8mb4 with tested dump/restore.
  4. Wrap new reads/writes behind repository classes your strangler can reuse.
  5. Leave Doctrine/Eloquent optional—introduce only when a bounded context is rewritten.

Tools: error matcher for SQLSTATE noise, legacy Composer dependencies when DB packages block PHP upgrades. Parent: ZF1 center.

Related tools

Related reading