1 database_example.module database_example_entry_load($entry = array())

Reads from the database using a filter array.

Backdrop provides an abstracted interface that will work with a wide variety of database engines.

db_query() is deprecated except when doing a static query. The following code is perfectly acceptable in Backdrop.

  // SELECT * FROM {database_example} WHERE uid = 0 AND name = 'John'
  db_query("SELECT * FROM {database_example} WHERE uid = :uid and name = :name",
    array(':uid' => 0, ':name' => 'John')

For more dynamic queries, Backdrop provides db_select().

  // SELECT * FROM {database_example} WHERE uid = 0 AND name = 'John'
    ->condition('uid', 0)
    ->condition('name', 'John')

With named placeholders, the code becomes the following

  // SELECT * FROM {database_example} WHERE uid = 0 AND name = 'John'
  $arguments = array(':name' => 'John', ':uid' => 0);
    ->where('uid = :uid AND name = :name', $arguments)

Conditions are stacked and evaluated as AND or OR depending on the type of query. The condition argument is an 'equal' evaluation by default, but this can be altered, like in the following snippet.

  // SELECT * FROM {database_example} WHERE age > 18
    ->condition('age', 18, '>')


array $entry: An array containing all the fields used to search the entries in the table.

Return value

array: An array containing the loaded entries, if found.

See also



Related topics


modules/examples/database_example/database_example.module, line 212
Hook implementations for the Database Example module.


function database_example_entry_load($entry = array()) {
  // Read all fields from the database_example table.
  $select = db_select('database_example', 'example');

  // Add each field and value as a condition to this query.
  foreach ($entry as $field => $value) {
    $select->condition($field, $value);

  return $select->execute()->fetchAll();