Hướng dẫn in ra câu truy vấn SQL queries để debugging trong Drupal 8

Hướng dẫn in ra câu truy vấn SQL queries để debugging trong Drupal 8

Trong bài viết này mình sẽ chỉ cho bạn cách in ra 1 chuỗi các truy vấn SQL sau đó mang lên PHPMyAdmin để test đúng hay sai. Bài viết này áp dụng trên CMS Drupal 8

Phpmyadmin

databaseService.php

<?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());

queryFactoryService.php

<?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());
Bạn thấy bài viết này như thế nào?: 
Average: 9.9 (7 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Commerce Kickstart

Thay đổi tiêu đề sản phẩm trong Commerce Kickstart

Commerce Kickstart automatically generates product names for you by default. The product will be named the same as the Product Display node title.

Hướng dẫn Syncing Databases giữa Drupal Websites với Backup and Migrate

Hướng dẫn Syncing Databases giữa Drupal Websites với Backup and Migrate

John Hannah explains how you can use destinations in Backup and Migrate module to sync Drupal databased.

Sử dụng CasperJS, Drush and Jenkins để test Drupal

Sử dụng CasperJS, Drush and Jenkins để test Drupal

A few weeks ago, spurred on by some frustrating interactions with Behat and Javascript, I started looking into alternative frameworks for running behavioral tests against Drupal

Công ty diệt chuột T&C

 

Diet con trung