You are here

public function DataHandler::save in Data 6

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

Save one or more records to the table.

If $update is given, method will try to update before.

This method is more comfortable, but slower than using insert() or update().

Parameters

$record: An array that is the record to save to this handler's table.

A string or an array of strings that defines the keys to use for: this update.

File

includes/DataHandler.inc, line 116
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 save(&$record, $update = array()) {
  if (is_string($update)) {
    $update = array(
      $update,
    );
  }
  if (is_array($update)) {
    $keys = array();
    foreach ($update as $key) {
      $keys[$key] = $record[$key];
    }
    if (count($keys)) {
      if ($this
        ->load($keys)) {
        return $this
          ->update($record, $update);
      }
    }
  }
  return $this
    ->insert($record);
}