|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-10-18 19:52 UTC] 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","example@example.com",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'] = "newmail@newmail.com"; // 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'] = "newmail@newmail.com";
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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
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,Sorry, the correct example should be : unset($row['deleted']); $rarr = array(); foreach ($row as $i => $vl) { $rarr[] = $vl; } and then replace_record using rarr.