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

 
3 điều quan trọng để Go live cho Drupal Emmy’s website

3 điều quan trọng để Go live cho Drupal Emmy’s website

When preparing for a big event, it is our job to make sure the general public sees exactly what is expected, and with the help of Amazon Web Service (AWS) we did! All planning comes with a few standard issue assessments/steps: Identify need, identify options, and begin to build!

Amazon: 1 triệu thiết bị Kindle được bán ra mỗi tuần

Amazon: 1 triệu thiết bị Kindle được bán ra mỗi tuần

Amazon đang rất thành công với các thiết bị Kindle, đặc biệt là Kindle Fire. Hiện số lượng thiết bị Kindle bán ra mỗi tuần đã tăng lên 1 triệu...

Sử dụng Hashtag trên Facebook hiệu quả 2015

Sử dụng Hashtag trên Facebook hiệu quả 2015

Nghĩ tới hashtag, mọi người sẽ nghĩ ngay tới Twitter. Có lẽ việc Twitter sử dụng hashtags

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

 

Diet con trung