// Load a record from the database with the specified ID $record = MyDataObject::getById($id); // Check if the record can be deleted if ($record->canDelete()) { // Delete the record $record->delete(); } else { echo "This record cannot be deleted."; }
// Load all records from the database $records = MyDataObject::getAll(); // Loop through the records foreach ($records as $record) { // Check if the record can be deleted if ($record->canDelete()) { // Delete the record $record->delete(); } else { echo "Record with ID ".$record->id." cannot be deleted."; } }In this example, we load all the records from the database and loop through them. For each record, we check if it can be deleted. If it can be deleted, we delete it. Otherwise, we print an error message. The PHP DataObject library is part of the PEAR (PHP Extension and Application Repository) package repository library.