PHP Doku:: Ersetzt einen Eintrag oder fügt ihn ein - function.dba-replace.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAbstraktionsebenenAbstraktionsschicht für dbm-style-DatenbankenDBA-Funktionendba_replace

Ein Service von Reinhard Neidl - Webprogrammierung.





(PHP 4, PHP 5)

dba_replaceErsetzt einen Eintrag oder fügt ihn ein


bool dba_replace ( string $key , string $value , resource $handle )

dba_replace() ersetzt in der durch handle spezifizierten Datenbank den Eintrag, der durch key und value beschrieben wird, oder fügt ihn ein.



Der Schlüssel des zu ersetzenden Eintrags.


Der Wert, der ersetzt werden soll.


Die Datenbank-Verbindungskennung, die von dba_open() oder dba_popen() zurückgegeben wurde.


Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Siehe auch

  • dba_exists() - Überprüft, ob ein angegebener Schlüssel existiert
  • dba_delete() - Löscht den zum angegebenen Schlüssel gehörigen DBA-Eintrag
  • dba_fetch() - Liest die Daten zu einem angegebenen Schlüssel aus
  • dba_insert() - Fügt einen Eintrag ein

4 BenutzerBeiträge:
- Beiträge aktualisieren...
khan666 at lycos dot co dot kr
3.12.2010 11:24
berkeley db : fetch array & display example


$db = dba_open($DB4_DATABASE,"r","db4");
$k  = dba_firstkey($db);

$k != NULL)
$AAA = explode("\xFE",dba_fetch($k, $db));
"[key] $k => [value] $AAA[0] / $AAA[1] / $AAA[2] / $AAA[3] / $AAA[4] / $AAA[5]<br>\r\n";

$k = dba_nextkey($db);
cbemerine at gmail dot com
6.09.2009 15:36
QDBM and GDBM appear to be the only DBA handlers that will allow dba_replace to work correctly.  The DBA Handlers must be compiled or built into the version you are using.  See dba_handlers ( for more specific information:

Also when you search online you will see mention of “security” related issue, supposedly, related to the dba_replace() function.  In every instance of the “security” issue documented online, the dba_open function specified the DBA handler option of “inifile”.  DBA handler “inifile” is intended for the management of ini files specifically.  Here are the dba_open and dba_replace code snippets related to this “security” issue:  

=dba_open("/www/about.ini", "wlt", "inifile");

I have also seen errors listed online with DB4 and use of the dba_replace function.  Though I am skeptical of those reports.  Unfortunately I do not have a database with the DB4 handlers compiled in to check if there is an issue with dba_replace and the DB4 DBA handler or not.  At least you are aware that there may be an issue and can check if need be.

Assuming the correct DBA handlers are “built” or compiled into your database when built for the packages you are using, there is probably not an issue with dba_replace() and actual database files.  If you experience a problem with dba_replace() make sure you build in DBA handlers QDBM or GDBM.

You can not build in both QDBM and GDBM together in the same build, however you probably can build in both INIFILE and FLATFILE with either QDBM or GDBM.  It is unclear if you can build in either db3 or db4 with QDBM or GDBM.  It appears that DB4, CDB, INIFILE and FLATFILE are often built together.

see User contributed notes for dba_handlers() and dba_open() related to CDB.
jelte dot werkhoven at itfy dot com
26.09.2002 16:24
Not only will dba_replace add extra entries when trying to replace an existing smaller one, it will always add a new entry if the size of the value differs from the existing entry. This is probably due to the nature of the datum struct in DBM-type databases (I work with gdbm), which consist of a void pointer and a integer containing the size of the memory pointed to. Padding the value should solve this.
swain at panix dot com
7.11.2001 8:03
Note that if you replace an existing entry with a larger one, it will actually create a new entry and the old one is simply lost. This is a memory leak in other words.

You might want to try padding your values to a certain size before putting them in the db file; for example, if you are storing web pages in the db, pad them out to the next 500 byte size with spaces, and strip the spaces when you read it out. This will go a long way in saving disk space. I've seen db files grow to several megabytes with only a couple hundred text files in them.

PHP Powered Diese Seite bei
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)