php[world] 2015 Call for Speakers


(PHP 4, PHP 5)

dbase_replace_recordSostituisce un record in un database dBase


bool dbase_replace_record ( int $dbase_identifier , array $record , int $dbase_record_number )

Sostituisce i dati associati con il record record_number con i dati nel record nel database. Se il numero di items nel record non è uguale al numero di campi nel database, l'operazione fallirà e sarà restituito FALSE.

dbase_record_number è un integer che va da 1 al numero di records nel database (come restituito da dbase_numrecords()).

add a note add a note

User Contributed Notes 6 notes

rlundp at lunds dot us
2 years ago
It took me a while to figure this out, so even though this is near-obsolete, maybe it will be useful to someone else.

I have a dBase file that contains a boolean value. I created a new row in the file with the boolean value at 0, and that worked without issues.

But then I tried to set that value to 1, and it did not work. I tried 1, "1", true - all without success.

Turns out that you need to use "Y" to set a boolean value to 1.

When you load the row later and output it using var_dump, the value will show as integer with the value 1.
3Famous at gmail dot com
7 years ago
Actually you have to change the read array from key based to element (numeric) based and everything works correctly!

= dbase_open( "yourfile.dbf", 2); // 0=RO, 1=WO, 2=RW
if ($db) {
$row = dbase_get_record_with_names($db, 1);
$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);

That code actually works!
hassan at datakillarna dot se
9 years ago
If you get "unexpected error", try to change the assoc array, $row, to an indexed array with array_values().

= 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! ;)
10 days ago
Make sure you opened the database for WRITE!
dbase_open( "yourfile.dbf", 2)
wysocki at wildworld dot net
10 years ago
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);
dbase_replace_record($db, $row, 1);
dbase_add_record($db, $row);

//To further prove the point,
//The first add works, the second one fails:
$testrow2=array('FIELDA' => 'xxx','FIELDB' => '9','FIELDC' => 'yyyyy');
xamkan at yahoo dot com
4 years ago
// simply use 'dbase_get_record' instead of 'dbase_get_record_with_names', for 'dbase_replace_record', 'dbase_add_record', or 'dbase_delete_record', to work


// open in read-write mode
$db = dbase_open('/tmp/test.dbf', 2) or die("Error! Could not open dbase database file /tmp/test.dbf.");        // 0=RO, 1=WO, 2=RW

// gets the old row
$row = dbase_get_record($db, 1);

// remove the 'deleted' entry from the array

// Update the date field with the current timestamp
$row['date'] = date('Ymd');

// Replace the record
dbase_replace_record($db, $row, 1);

To Top