Database Basic Examples

Submitted by Anonymous (not verified) on Fri, 06/10/2016 - 23:50
Question

Drupal 8 Database basic commands / Examples

Select:
    $con = \Drupal\Core\Database\Database::getConnection();
    $query = $con->select('table_name', 't')
        ->fields('t', ['field_1', 'field_2']);
    $result = $query->execute()->fetchAll();

NULL Condition

$query->isNull('t.field_1');
$query->isNotNull('t.field_2');

Add new comment