Writing to dbase (dbf) deletes index (cdx)
| From: | Rahul S. Johari | Date: | Wed, 25 Mar 2009 12:11:19 +0000 |
| Subject: | Writing to dbase (dbf) deletes index (cdx) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-290671@lists.php.net to get a copy of this message | ||
Ave,
I noticed something peculiar and I can't find a solution for this. I'm wondering if anyone can help me out.
I'm using the dbase functions to read & write from dbf (foxpro) tables. The DBF tables usually have an Index which is contained in filename.cdx. It appears that anytime I Write to the dbf table, it deletes the Index. Is there any way around this?
Here's a simple code that I use for appending to a DBF table:
// open in read-write mode
$db = dbase_open("dbf/myfile.dbf", 2);
// gets the old row
if ($db) {
$record_numbers = dbase_numrecords($db);
for ($i = 1; $i <= $record_numbers; $i++) {
$row = dbase_get_record_with_names($db, $i);
if ($row['SECCODE'] == $_COOKIE['seccodeCookie']) {
unset($row["deleted"]);
// Update fields
$row['f1'] = $_POST['name'];
$row['f2'] = $_POST['email'];
//echo "Replacing Record number $i";
// Replace the record
$row = array_values($row);
dbase_replace_record($db, $row, $i) or die("Fatal Error");
}
}
}
dbase_close($db);
?>
Thanks.
---
Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.
[Email] sleepwalker@rahulsjohari.com
[Web] http://www.rahulsjohari.com