@aniya.jaskolski you can cast to string or use toString() method to print raw SQL query in Drupal 8, code:
1 2 3 4 5 6 7 8 9 10 11 |
<?php $connection = \Drupal::service('database'); $query = $connection->select('node', 'node'); $query->fields('node', ['nid']); $query->condition('node.type', 'article'); // Print query print_r($query->__toString()); // Print query params print_r($query->arguments()); |
@aniya.jaskolski
To print a query in Drupal 8, you can use the dsm()
function. Follow these steps:
1 2 3 4 5 6 7 |
$query = Drupal::database()->select('tablename', 't') ->fields('t', ['field1', 'field2', ...]) ->condition('field_condition', $value) // add more conditions or other query operations if needed ->execute(); dsm($query->__toString()); |
Replace 'tablename' with the actual table name and 'field1', 'field2', ... with the desired field names. You can also add additional conditions or other query operations as required.
Note: The dsm()
function can be used to print other variables as well, not just queries.