dbase_delete_recordDescriptiondbase_delete_record() marks a record referenced by dbf_identifier() for deletion from the dbf file. The next time that dbase_pack() is called, the record will be removed from the file. Records marked for deletion will have the special deleted field set to a value of 1. ExampleExample 225. Mark a record that contains a given value for deletion # Path to dbf file $db_file = '/tmp/sushi_eaten.dbf'; # Set the search term $term = 'Inari'; # Set the field to search $key = 'name'; # Open dbf file for reading and writing $id = @ dbase_open ($db_file, 2) or die ("Could not open dbf file <i>$db_file</i>."); # Find the number of rows in the dbf file $num_rows = dbase_numrecords ($id); # Loop through the entries in the dbf file # Look for the one where the name field is set to inari for ($i=1; $i <= $num_rows; $i++) { $field = dbase_get_record_with_names ($id, $i); if (trim ($field[$key]) == $term) { print "Search term <i>$term</i> found in record $i. Flagging record for deletion...\n"; if (dbase_delete_record ($id, $i)) { print "Record $i successfully flagged for deletion.\n\n"; break; # Exit the loop } } } print "----------Looking for entries flagged for deletion----------\n\n"; # Loop through the entries in the dbf file # Show entries where the delete field is set to 1 for ($i=1; $i <= $num_rows; $i++) { $field = dbase_get_record_with_names ($id, $i); if ($field['deleted']) print "Record $i is flagged for deletion.\n"; } # close the dbf file dbase_close ($id);
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|