Deprecated Database API Calls to Be Removed in Drupal 12

Victor Jimenez highlights Drupal 12’s removal of deprecated db_* wrappers and the upgrade risks that follow.
API
Freepik

Software engineer Victor Jimenez has warned on the VictorStack AI blog that Drupal 12 will remove long-deprecated procedural Database API wrappers such as db_query() and db_select(), completing a transition that began with Drupal 8.

The removal is tracked in Drupal core issue #3525077, “[D12] Remove deprecated paths from the Database API & friends.” Once Drupal 12 is released, any remaining use of these wrappers will result in fatal errors, turning what has long been a soft deprecation into a hard break.

In his article, Jimenez explains that projects still relying on procedural database calls must migrate to the service-based approach, either through dependency injection or via \Drupal::database().


// Legacy (removed in Drupal 12)
$result = db_query("SELECT nid FROM {node} LIMIT 1");

// Modern approach
$result = \Drupal::database()->query("SELECT nid FROM {node} LIMIT 1");
  

Although these wrappers have been deprecated for multiple major versions, they remained available for backward compatibility. Their removal in Drupal 12 marks the final phase of eliminating procedural database abstractions in favour of the service container architecture introduced in Drupal 8.

CLI tool for targeted auditing

Alongside the warning, Jimenez introduced a new command in the Drupal 12 Readiness CLI designed to scan codebases specifically for deprecated db_* usage.

The check:db-api command searches PHP, module, install, and theme files for more than 30 procedural Database API functions scheduled for removal and reports suggested replacements.


composer require --dev victorstack-ai/drupal-12-readiness-cli
./vendor/bin/drupal-12-readiness check:db-api web/modules/custom/my_module
  

Jimenez positions the tool as a lightweight audit mechanism suitable for CI pipelines or pre-commit checks, complementing broader refactoring tools such as Drupal Rector.

Earlier this month, The DropTimes reported on another CLI utility released by Jimenez focused on validating Drupal migration mappings before deployment. The newer Database API audit command reflects a similar pattern of targeted tooling focused on upgrade and workflow checks.

Upgrade planning implications

As Drupal 12 approaches, the removal of procedural Database API wrappers reinforces the need for early upgrade audits. For teams maintaining custom or contributed modules, reviewing Database API usage is no longer optional if fatal errors are to be avoided after upgrade.

Disclosure: This content is produced with the assistance of AI.

Note: The vision of this web portal is to help promote news and stories around the Drupal community and promote and celebrate the people and organizations in the community. We strive to create and distribute our content based on these content policy. If you see any omission/variation on this please reach out to us at #thedroptimes channel on Drupal Slack and we will try to address the issue as best we can.

Related People

Upcoming Events