Tuesday, June 23, 2009

Unique IDs for Records

One nice feature of Xataface is that it provides a mechanism for identifying a record uniquely within a database. It also provides methods for loading a record from its ID and obtaining a record's id.

The function df_get_record_by_id() returns a Dataface_Record object. And the Dataface_Record object contains a method getId() that returns the ID. This allows you to easily and universally pass a record between requests.

E.g.

// Load the record with id 10 from the people table
$record = df_get_record('people', array('id'=>10));

// Get the unique id of this record.
$recordid = $record->getId();

// Let's just print the id to see what it looks like
echo $recordid;

// Should be something like: people?id=10

// Now load the record again but this time using its universal id
$record2 = df_get_record_by_id($recordid);

No comments:

Post a Comment