Drupal 8 db query

查询:

$database = \Drupal::database();
$result = $database->query('SELECT * FROM {xx} where ID=:id', [':id' => 1]);


# OBJ查询
$result = $database->select('players', 'p')
->fields('p')
->condition('id', 1)
->execute();

获取结果:

#1
foreach($result as $record) {
  $id = $record->id
}

#2
$records = $result->fetchAll();
$records = $result->fetchAllAssoc('id');