You are here

public function DataHandler::load in Data 6

Same name and namespace in other branches
  1. 8 includes/DataHandler.inc \DataHandler::load()
  2. 7 includes/DataHandler.inc \DataHandler::load()

Load a record.

1 call to DataHandler::load()
DataHandler::save in includes/DataHandler.inc
Save one or more records to the table.

File

includes/DataHandler.inc, line 47
Definition of DataHandler class.

Class

DataHandler
Simple access methods to table data. Can be used on any table, not just Data managed tables.

Code

public function load($keys) {
  $where = $values = array();
  $schema = drupal_get_schema($this->table);
  $fields = $schema['fields'];
  foreach ($keys as $key => $value) {

    // Return if a key does not exist.
    if (!isset($fields[$key]['type'])) {
      return FALSE;
    }
    $where[] = db_escape_string($key) . " = " . db_type_placeholder($fields[$key]['type']);
    $values[] = $value;
  }
  if (!empty($where)) {
    $result = db_query('SELECT * FROM {' . db_escape_table($this->table) . '} WHERE ' . implode(' AND ', $where), $values);
    $results = array();
    while ($row = db_fetch_array($result)) {
      $results[] = $row;
    }
    return count($results) ? $results : FALSE;
  }
  return FALSE;
}