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

 
Dịch vụ diệt muỗi tận gốc tại nhà tháng 03 năm 2016

Dịch vụ diệt muỗi tận gốc tại nhà tháng 03 năm 2016

Thông thường dịch vụ diệt muỗi sẽ được bảo hành trong 03 tháng tính từ ngày thực hiện phun thuốc.

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!

Samsung được cấp giấy phép thiết kế VXL ARM 64 bit

Samsung được cấp giấy phép thiết kế VXL ARM 64 bit

Việc Samsung được cấp giấy phép thiết kế VXL ARM 64 bit cho thấy hãng sản xuất chip này có thể mở rộng phạm vi từ smartphone và MTB để nhảy vào thị trường máy chủ.

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

 

Diet con trung