Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Created June 9, 2026 08:45
Show Gist options
  • Select an option

  • Save vyspiansky/f5029dda705e81a66351b1f8d6576b73 to your computer and use it in GitHub Desktop.

Select an option

Save vyspiansky/f5029dda705e81a66351b1f8d6576b73 to your computer and use it in GitHub Desktop.
Assemble SQL query in Drupal 10
<?php
/** @var \Drupal\Core\Database\Query\ExtendableInterface $query */
$sql = $query->__toString();
$args = $query->getArguments();
foreach ($args as $placeholder => $value) {
$quoted = is_numeric($value) ? (string) $value : "'" . addslashes($value) . "'";
$sql = str_replace($placeholder, $quoted, $sql);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment