# Basic queries

Basic queries to a database are done using [DatabaseProvider::query](https://cherrycake.tin.cat/version-0.x/reference/core-classes/databaseprovider/databaseprovider-methods#query). Since database providers are available as properties of the Database module, a simple query to a provider named `main` would look like this:

```php
$result = $e->Database->main->query("select * from users");
```

Database queries are returned in the form of a [DatabaseResult](https://cherrycake.tin.cat/version-0.x/reference/core-classes/databaseresult) object you can manipulate. For example, use the [DatabaseResult::isAny](https://cherrycake.tin.cat/version-0.x/reference/core-classes/databaseresult/databaseresult-methods#isany) method to check if there were any results, or the [DatabaseResult::countRows](https://cherrycake.tin.cat/version-0.x/reference/core-classes/databaseresult/databaseresult-methods#countrows) to get the number of rows in the result.

To loop through all the rows, iterate over the [DatabaseResult::getRow](https://cherrycake.tin.cat/version-0.x/reference/core-classes/databaseresult/databaseresult-methods#getrow) method:

```php
while ($row = $result->getRow()) {
    echo $row->getField("name")."\n";
}
```

Rows are returned as [DatabaseRow](https://cherrycake.tin.cat/version-0.x/reference/core-classes/databaserow) objects which, as you can see in the example above, allow you to retrieve information from each row in the results. Here's the result:

```
Douglas Engelbart
John Horton Conway
Frank Abagnale
Carl Sagan
Richard Feynmann
```

{% hint style="success" %}
See this example working in the [Cherrycake documentation examples ](https://documentation-examples.cherrycake.io/example/databaseGuideBasicQueries)site.
{% endhint %}
