Basic queries
Basic queries to a database are done using DatabaseProvider::query. Since database providers are available as properties of the Database module, a simple query to a provider named main
would look like this:
Database queries are returned in the form of a DatabaseResult object you can manipulate. For example, use the DatabaseResult::isAny method to check if there were any results, or the DatabaseResult::countRows to get the number of rows in the result.
To loop through all the rows, iterate over the DatabaseResult::getRow method:
Rows are returned as 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:
See this example working in the Cherrycake documentation examples site.
Last updated