|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34911 php_dbase.dll : dbase_replace_record : tricks to work
Submitted: 2005-10-18 19:52 UTC Modified: 2005-10-22 18:43 UTC
From: allan dot s dot oliveira at gmail dot com Assigned:
Status: Not a bug Package: dBase related
PHP Version: 5.0.5 OS: Windows NT WXP 5.1 build 2600
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: allan dot s dot oliveira at gmail dot com
New email:
PHP Version: OS:


 [2005-10-18 19:52 UTC] allan dot s dot oliveira at gmail dot com
the last bug report was 2001... but, here it goes.

if you get the record and simply try to replace it using the loaded array, the number of arguments is invalid.

Reproduce code:
$dbname = "./tmp/test.dbf"; // dbf name
$def = array( array("date", "D"), array("name", "C", 50), array("age", "N", 3, 0), 
array("email", "C", 128), array("ismember", "L") ); // structure
dbase_create($dbname, $def) // creating
$db=dbase_open($dbname,2) // open to insert
$reg=array("20030912","My Name","33","",False); // define record
dbase_add_record($db,$reg) // insert record
dbase_close($db); // close
$db=dbase_open($dbname,2) // open to replace
$row = dbase_get_record_with_names($db, 1); // gets actual row
$row['email'] = ""; // Update the date field with the current timestamp
dbase_replace_record($db,$row,1); // replace
// above instruction causes an error : incorrect number of arguments
$reg = array( $row['date'] , $row['name'] , $row['age'] , $row['email'] , $row['ismember'] ); // redefine record without 'deleted' column 
dbase_replace_record($db,$reg,1); // Replace the record : OK
// This Replace goes OK
echo "Done";

Expected result:
this should work properly, without any tricks :

$row = dbase_get_record_with_names($db, 1)
$row['email'] = "";

Actual result:
I recently start to work with some dbase files, and following the examples, this error should not appear.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-21 23:13 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

dbase_get_record*() funcs return a row and add "deleted" field to indicate if this row were marked for deletion or not.
You can see a note about it in dbase_replace_record() reference:
"Note: If you're using dbase_get_record() return value for this parameter, remember to reset the key named deleted."

Also, dbase_replace/add_record() work only with indexed arrays and this is documented too.
 [2005-10-22 18:40 UTC] allan dot s dot oliveira at gmail dot com
Thanks Tony2001 in advance.

If I understood the explanation, it means that I should use dbase_get_record() instead of dbase_get_record_with_names() as it is in the "Example 438. Updating a record in the database" in the section "Function Reference / dBase Functions".

I tried again as the PHP Manual Example with some changes :
1. dbase_get_record instead of dbase_get_record_with_names
2. '0' for 'date'

Even then, the get_record followed by replace_record did not works as it should.
The 'dbase_get_record()' gave me an indexed array, but the same error occurs :
PHP Warning:  dbase_replace_record(): unexpected error in D:\Apache\Apache2\htdocs\tests\_debug_tmp.php on line 17

No problem, I created a function to execute the replace that recreates an indexed array and take the extra 'deleted' element off.
$rarr = array();
foreach ($row as $i => $vl) { if ($i <> "deleted") { $rarr[] = $vl; } }

I believe that this transformation should be inside the dbase_replace_record, and not so simple like mine, but considering the table structure crossed with the array elements.

Best Regards,
 [2005-10-22 18:43 UTC] allan dot s dot oliveira at gmail dot com
Sorry, the correct example should be :

$rarr = array();
foreach ($row as $i => $vl) { $rarr[] = $vl; }

and then replace_record using rarr.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Jun 07 20:03:39 2023 UTC