Display database query results in custom module I have a custom block and I'm able to update its content using #pre_render if I'm using basic text.

However I'm unable to print database query results using the same way. Below is my code.

function _maintenance_prerender(array $build) { 
$build['content']['#markup'] = myDatabaseQuery();
return $build;
}

function myDatabaseQuery() {
  $query = \Drupal::database()-&gt;select('menu_link_content_data', 'm');
  $query-&gt;condition('m.title', 'Visit');
  $results = $query-&gt;execute();
}


Is there a special way to print database query results on a custom block?
To be able to exploit your result, you should fetch your result with one of the function of the Statement class.

If you use the function fetchAll() for example, you will have an array of objects with all your result.

$results = $query-&gt;execute()-&gt;fetchAll();


You can do a function to create your markup with that array. 

You can also not use a function from Statement and do a foreach directly on the result generate by the execute() function to create your markup

$results = $query-&gt;execute();

foreach($results as $res) {
    $markup .= "&lt;tr&gt;&lt;td&gt;$res-&gt;field_1&lt;/td&gt;&lt;td&gt;$res-&gt;field_2&lt;/td&gt;&lt;/tr&gt;";
}


If you want see how is design your array, you can install the module kint (from the devel module) and display your result with 

ksm($results);


Additionnally, to work, your query should have the list of fields it should select.

$query-&gt;fields('m', ['field_1', 'field_2']);