Blog Sections Open

Replacing Raw mysql_query Updates with Evolution CMS DBAPI Calls

A practical cleanup pattern for old Evolution CMS code that still updates custom tables through giant raw SQL strings instead of DBAPI helpers.

Older Evolution CMS projects often carry a layer of raw PHP database code that predates later cleanup practices. The donor case showed exactly that problem: a large update flow still relied on hand-built SQL strings and mysql_query()-style thinking, even though the project already used the Evolution DBAPI for safer reads.

Why this matters

  • Huge hand-concatenated update queries are hard to maintain.
  • They make validation and escaping easier to get wrong.
  • They tie business logic too tightly to one legacy DB function style.

Cleaner direction

$result = $modx->db->update($fields, $table, 'id = "' . $id . '"');

That does not magically solve every data-model problem, but it does move the update logic toward a cleaner contract: collect the fields you actually want to write, pass them into the DBAPI, and keep your persistence layer readable.

When cleaning old Evolution codebases, replacing giant raw update strings with structured DBAPI calls is one of the highest-value refactors you can do.

Newer post

Sending FormLister Uploads as Links Instead of Heavy Email Attachments

How to save uploaded files from FormLister and send recipients a download link instead of attaching every file directly to the email.

Older post

Fixing Image Paths for the Second Site in a Multisite Evolution CMS Setup

How to resolve image path problems when a second site in a multisite Evolution CMS setup still points at the wrong assets location.