-
-
Save thelebster/ea14709b4d4eca53016a547eb6b158a6 to your computer and use it in GitHub Desktop.
Drupal 8 - Print raw SQL queries for debugging
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 | |
| /** | |
| * Debugging using the database connection. | |
| */ | |
| /** @var \Drupal\Core\Database\Connection */ | |
| $connection = \Drupal::service('database'); | |
| $query = $connection->select('node', 'node'); | |
| $query->fields('node', ['nid']) | |
| ->condition('node.type', 'page') | |
| // Debug. | |
| dump($query->__toString()); |
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 | |
| /** | |
| * Debugging using the query factory. | |
| */ | |
| // Update the Drupal\Core\Entity\Query\Sql\Query & change the property $sqlQuery to be public then... | |
| $queryFactory = \Drupal::service('entity.query'); | |
| $query = $queryFactory->get('node'); | |
| $query->condition('type', 'page'): | |
| // Debug. | |
| dump($query->execute()); | |
| dump($query->sqlQuery->__toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment