Actually you have to change the read array from key based to element (numeric) based and everything works correctly!
$db = dbase_open( "yourfile.dbf", 2); // 0=RO, 1=WO, 2=RW
if ($db) {
$row = dbase_get_record_with_names($db, 1);
unset($row["deleted"]); // drop the field
// do whatever it is you want to the $row["elements"]
// then convert to numeric to store:
$rarr = array();
foreach ($row as $i=>$vl) $rarr[] = $vl;
dbase_replace_record($db, $rarr, 1);
dbase_close($db);
}
That code actually works!
--- Want to be famous?
http://www.3famous.com/ - 100% PHP BABY!
dbase_replace_record
(PHP 4, PHP 5)
dbase_replace_record — Substitui um registro no banco de dados
Descrição
Substitui o registro no banco de dados com os dados indicados.
Parâmetros
- dbase_identifier
-
O identificador do banco de dados, retornado por dbase_open() ou dbase_create().
- record
-
Uma matriz indexada de dados. O número deve ser igual ao número de campo no banco de dados, se não dbase_add_record() irá falhar.
Nota: Se você esta usando o valor de retorno de dbase_get_record() para este parâmetro, lembre-se de reiniciar o valor de deleted.
- record_number
-
Um inteiro que vai de 1 até o número de registros no banco de dados (como retornado por dbase_numrecords()).
Valor Retornado
Retorna TRUE em caso de sucesso ou FALSE em falhas.
Exemplos
Exemplo #1 Atualizando um registro no banco de dados
<?php
// open in read-write mode
$db = dbase_open('/tmp/test.dbf', 2);
if ($db) {
// gets the old row
$row = dbase_get_record_with_names($db, 1);
// remove the 'deleted' entry
unset($row['deleted']);
// Update the date field with the current timestamp
$row['date'] = date('Ymd');
// Replace the record
dbase_replace_record($db, $row, 1);
dbase_close($db);
}
?>
dbase_replace_record
11-Feb-2008 09:03
10-Feb-2006 04:30
If you get "unexpected error", try to change the assoc array, $row, to an indexed array with array_values().
Example:
$row = array_values($row);
dbase_replace_record($db, $row, 1);
The dbase_replace-function cannot handle an assoc array.
Hope this will save someone a headache! ;)
11-Feb-2005 01:15
The dbase add and replace functions do NOT like to use the associative array.
<?
//This gives "unspecified error" on replace and add:
$row = dbase_get_record_with_names($db, 1);
unset($row['deleted']);
dbase_replace_record($db, $row, 1);
dbase_add_record($db, $row);
//To further prove the point,
//The first add works, the second one fails:
$testrow1=array('one','2','three');
dbase_add_record($db,$testrow1);
$testrow2=array('FIELDA' => 'xxx','FIELDB' => '9','FIELDC' => 'yyyyy');
dbase_add_record($db,$testrow2);
?>
