Using the fetch() method in database query to get an array I have a very simple query that does the job, to get a collection of a specific content type's node id and title, that's it.

$connection = \Drupal::database();
$query = $connection-&gt;select('node_field_data', 'n');
$query-&gt;condition('n.type', 'employee');
$query-&gt;condition('n.status', 1);
$query-&gt;fields('n', ['nid', 'title']);
$results = $query-&gt;execute()-&gt;fetchAll();


And what i get is an array filled with objects (for each individual results) with two properties the nid and title values. But i want to have an single layer/dimension array filled with key => valued pairs (nid => title). Example bellow.

$results = [
  0 = {stdClass} (
     nid =&gt; 123,
     value =&gt; Susan Green
  )
];


And what i want:

$results = [
  123 =&gt; Susan Green,
  567 =&gt; Bob Young
];


I've tried fetchAllAssoc, fetchAssoc, etc but either the result is empty or i get something completely opposite of what i want.

Any ideas? without using a parses to convert objects into what i want, that's what i'll do if none one can find an appropriate answer.
You can use fetchAllKeyed try with:

  $connection = \Drupal::database();
    $query = $connection-&gt;select('node_field_data', 'n');
    $query-&gt;condition('n.type', 'employee');
    $query-&gt;condition('n.status', 1);
    $query-&gt;fields('n', ['nid', 'title']);
    // use fetchAllKeyed
    $results = $query-&gt;execute()-&gt;fetchAllKeyed(0,1);