Problem with a query On Drupal 8, I have this line inside my form (my_module/src/Form/MyCustomForm.php).

$users = db_query('SELECT * FROM {users}');


var_dump($users) shows an object (of my query) and not the list of all users.

object(Drupal\Core\Database\Statement)[322] public 'dbh' =&gt; object(Drupal\Core\Database\Driver\mysql\Connection)[20] protected 'needsCleanup' =&gt; boolean false protected 'target' =&gt; string 'default' (length=7) protected 'key' =&gt; string 'default' (length=7) protected 'logger' =&gt; null protected 'transactionLayers' =&gt; array (size=0) empty protected 'driverClasses' =&gt; array (size=0) empty protected 'statementClass' =&gt; string 'Drupal\Core\Database\Statement' (length=30) protected 'transactionSupport' =&gt; boolean true protected 'transactionalDDLSupport' =&gt; boolean false protected 'temporaryNameIndex' =&gt; int 0 protected 'connection' =&gt; object(PDO)[15] protected 'connectionOptions' =&gt; array (size=10) 'database' =&gt; string 'theming' (length=7) 'username' =&gt; string 'root' (length=4) 'password' =&gt; string 'private' (length=8) 'prefix' =&gt; array (size=1) ... 'host' =&gt; string 'localhost' (length=9) 'port' =&gt; string '3306' (length=4) 'namespace' =&gt; string 'Drupal\Core\Database\Driver\mysql' (length=33) 'driver' =&gt; string 'mysql' (length=5) 'pdo' =&gt; array (size=4) ... 'init_commands' =&gt; array (size=1) ... protected 'schema' =&gt; null protected 'prefixes' =&gt; array (size=1) 'default' =&gt; string '' (length=0) protected 'prefixSearch' =&gt; array (size=2) 0 =&gt; string '{' (length=1) 1 =&gt; string '}' (length=1) protected 'prefixReplace' =&gt; array (size=2) 0 =&gt; string '' (length=0) 1 =&gt; string '' (length=0) public '_serviceId' =&gt; string 'database' (length=8) public 'allowRowCount' =&gt; boolean false public 'queryString' =&gt; string 'SELECT * FROM users' (length=19) 


Why?
There's nothing different from 7.x with db_query(), it returns a result set where you can fetch results from or loop over it. Refer to the database API documentation.

However, there are even less reasons for doing a direct database query in 8.x than in 7.x, and doing the query by hand is very likely going to be more complicated because of the data tables.

Use entity query instead:

&lt;?php
$uids = \Drupal::entityQuery('user')
  -&gt;execute();
?&gt;


Executing an entity query always returns entity IDs which can then be loaded:

&lt;?php
$users = \Drupal::entityManager()-&gt;getStorage('user')-&gt;loadMultiple($uids);
// Shorthand if you know that you have users:
$users = \Drupal\user\Entity\User::loadMultiple($uids);
?&gt;