Work with database in Drupal 8 2016-07-08 Drupal 8, database, mysql For creating database queries in Drupal 8, we should add dependency to ´Drupal\Core\Database\Connection´ class inside our class.123456789101112131415161718192021222324252627282930<?phpnamespace Drupal\our_custom_module_name;use Drupal\Core\Database\Connection;/** * Our class, where we will communicate with database. */class LetsTalkWithDatabase { /** * @var \Drupal\Core\Database\Connection */ protected $database; /** * Construct. */ public function __construct(Connection $database) { $this->database = $database; } /** * Create function. */ public static function create(ContainerInterface $container) { return new static( $container->get('database') ); }} The Query with condition 123456$nodes = $this->database('node', 'n') ->fields('n', array('nid', 'title')) ->condition('n.type', 'page') ->condition('n.uid', 1) ->execute() ->fetchAll(); The Query with joining12345$query = $this->database('node', 'n');$query->innerJoin('users', 'u', 'n.uid = u.uid');$query->fields('n', array('title'));$query->fields('u', array('name'));$nodes = $query->execute()->fetchAll(); Newer Database query for getting the closest destinations in Drupal 8 Older How to add a custom validation for the custom entity?