Last active
September 11, 2024 15:57
-
-
Save vyspiansky/2e3a0a66087eb68d68de5b60689bc84d to your computer and use it in GitHub Desktop.
Retrieve a plain SQL query from a Select query object in Drupal 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\Core\Database\Database; | |
use Drupal\Core\Database\Query\SelectInterface; | |
/** | |
* Returns a plain SQL query from a Select query object. | |
*/ | |
function get_plain_sql_query(SelectInterface $query): string | |
{ | |
$sql = $query->__toString(); | |
$args = $query->getArguments(); | |
foreach ($args as $key => $value) { | |
$sql = str_replace($key, Database::getConnection()->quote($value), $sql); | |
} | |
return $sql; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment