|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-03-08 17:06 UTC] poulain dot mathieu at gmail dot com
Description:
------------
A simple PHP installation without other modules
php_dbase.dll version : 5.4.6
Error : PHP Warning: dbase_replace_record(): Wrong number of fields specified
No information found since 2005 and with a old version of PHP.
I just want to replace a string on a field into a DBF file.
Test script:
---------------
$directory = "D:\Scripts";
$handler = opendir($directory);
while ($file = readdir($handler)) {
if (strpos($file, ".DBF") == true){
$db_path = $directory . '\\' . $file;
$dbh = dbase_open($db_path, 2) or die("ERROR Could not open dbase database file '$db_path'.");
$num_rec = dbase_numrecords($dbh);
for ($i=1; $i<=$num_rec; $i++){
$row = @dbase_get_record_with_names($dbh,$i);
foreach ($row as $key => $val){
$q = "'" . $val . "'";
if (strpos($q, "TOTO") == true){
unset($row['deleted']);
$row[$key] = str_replace("TOTO", "TITI", $row[$key]);
dbase_replace_record($dbh, $row, $i);
}
}
}
dbase_close($dbh);
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
I also get this error always. For my understanding, this simple code should work without problems: $db = dbase_open('TEST.DBF', 2); $data = dbase_get_record_with_names($db, 1); dbase_replace_record($db, $data, 1); But it will not work. All other dbase functions works fine. Test file: https://www.dropbox.com/s/45d6u0k08pugm87/TEST.DBF?dl=0 (file type Fox Pro 2.x standard) Tested with PHP 7.1.7 and 5.6.31Testing again with bigger dbf file today. Code: $db = dbase_open('../ARTIKEL.DBF', 2); // 2 = lese und schreibmodus $count = dbase_numrecords($db); if($db){ for($i = 1; $i <= $count; $i++){ $row = dbase_get_record_with_names($db, $i); $row['L_MATCH'] = str_replace(" ", "", $row['L_MATCH']); if($row['L_MATCH'] == '33254'){ echo '<pre>'; print_r($row); echo '</pre>'; #unset($row['deleted']); //doesn't work with or without $row['L_VERFUEG'] = 'TEST'; $row = array_values($row); if(dbase_replace_record($db, $row, $i)){echo 'true';}else{echo 'false';} echo '<pre>'; print_r($row); echo '</pre>'; } } dbase_close($db); } I have exactly 150 values before and after using array_values but this error is coming again. So the problem must be something in the loop, isn't it? Topic opener had also a loop...