ID: 34911
User updated by: allan dot s dot oliveira at gmail dot com
Reported By: allan dot s dot oliveira at gmail dot com
Status: Bogus
Bug Type: dBase related
Operating System: Windows NT WXP 5.1 build 2600
PHP Version: 5.0.5
New Comment:
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,
Previous Comments:
------------------------------------------------------------------------
[2005-10-21 23:13:33] [EMAIL PROTECTED]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
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-18 19:52:39] allan dot s dot oliveira at gmail dot com
Description:
------------
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:
---------------
<?php
$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","[EMAIL PROTECTED]",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'] = "[EMAIL PROTECTED]"; // 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
dbase_close($db);
echo "Done";
?>
Expected result:
----------------
this should work properly, without any tricks :
$row = dbase_get_record_with_names($db, 1)
$row['email'] = "[EMAIL PROTECTED]";
dbase_replace_record($db,$row,1);
Actual result:
--------------
I recently start to work with some dbase files, and following the
examples, this error should not appear.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34911&edit=1