PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DB++> <dBase Functions
Last updated: Fri, 22 Aug 2008

view this page in

dbase_replace_record

(PHP 4, PHP 5)

dbase_replace_recordModifica un registro de la base de datos

Descripción

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

Modifica un registro de la base de datos con los datos indicados.

Lista de parámetros

dbase_identifier

El identificador de base de datos, devuelto por la función dbase_open() o dbase_create().

record

Una matriz indexada con los datos. El número de elementos debe ser igual que el número de campos de la base de datos, ya que de otra forma la función dbase_add_record() fallará.

Note: Si se emplean los valores devueltos por la función dbase_get_record(), se dede resetear el valor de la clave asociativa deleted.

record_number

Un número entero que puede tomar un valor entre 1 y el número de registros que contiene la base de datos (el número total se puede obtener con la función dbase_numrecords()).

Valores retornados

Devuelve TRUE si todo se llevó a cabo correctamente, FALSE en caso de fallo.

Ejemplos

Example #1 Actualizar un registro de la base de datos dBase

<?php

// abrir en modo lectura y escritura
$db dbase_open('/tmp/test.dbf'2);

if (
$db) {
  
// obtener el valor actual del registro
  
$fila dbase_get_record_with_names($db1);
  
  
// borrar la clave 'deleted'
  
unset($fila['deleted']);
  
  
// actualizar el campo de la fecha con la marca de tiempo actual
  
$fila['fecha'] = date('Ymd');
  
  
// Modificar el registro
  
dbase_replace_record($db$fila1);
  
dbase_close($db);
}

?>



DB++> <dBase Functions
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
dbase_replace_record
3Famous at gmail dot com
11-Feb-2008 06:03
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!
hassan at datakillarna dot se
11-Feb-2006 01: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! ;)
wysocki at wildworld dot net
11-Feb-2005 10: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);
?>

DB++> <dBase Functions
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites