|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-10-08 10:10 UTC] rcovell at rolet dot com
Description:
------------
Basically I cannot get php to open an existing (not created by php) db3 hash file when using either "w" or "c". It seems that php is looking for a btree format. My database is a hash file.
More information:
Trying to read/write information to an existing db3 database (sendmail aliases file).
I can read the file just fine. But when I try to issue:
$id = dba_open ("aliases5.db", "w", "db3");
I get:
[Wed Oct 8 08:56:44 2003] [error] PHP Warning: dba_open(aliases5.db,w): Driver initialization failed for handler: db3: Invalid argument in /usr/local/www/data/maillists/test3.php on line 3
After further testing I dumped the entire aliases db to a text file using perl and recreated a copy of it with php:
$id = dba_open ("aliases5.db", "c", "db3");
This worked when creating a new file. The file sizes where were different from the original so performed a db3_dump on the newly created php db3 database. It seems that php is defaulting to a btree format when trying to open with either w or c. My output from the db3_dump on the php created db3:
VERSION=3
format=bytevalue
type=btree
HEADER=END
And from the one that sendmail created:
VERSION=3
format=bytevalue
type=hash
h_nelem=172
HEADER=END
Reproduce code:
---------------
//Note you need a hash database for this to fail
$id = dba_open ("aliases5.db", "w", "db3");
if (!$id) {
echo "dba_open failed\n";
exit;
}
dba_insert ("bkey", "bvalue", $id);
$key = dba_firstkey ($id);
while ($key != false)
{
echo "<br>Key: " . $key . "->Value: " . dba_fetch ( $key, $id);
$key = dba_nextkey ($id);
}
dba_close ($id);
Expected result:
----------------
To be able to insert into an existing (not created by php) db3 hash database.
Actual result:
--------------
[Wed Oct 8 08:56:44 2003] [error] PHP Warning: dba_open(aliases5.db,w): Driver initialization failed for handler: db3: Invalid argument in /usr/local/www/data/maillists/test3.php on line 3
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 19:00:02 2025 UTC |
A working fix is to alter line 90 of ext/dba/dba_db3.c (in your PHP source directory) Original line: if ((err=dbp->open(dbp, info->path, NULL, type, gmode, filemode)) == 0) { Change type to DB_HASH if ((err=dbp->open(dbp, info->path, NULL, DB_HASH, gmode, filemode)) == 0) { Recompile and install PHP. Now PHP will only be able to work with type hash db3s PHP defaults to type DB_BTREE for creating and should pass DB_UNKOWN for opening. passing DB_UNKNOWN as the type to DB::open should be able to open a db3 of any type. This code seems to work fine in older releases of PHP, and I can not see any differance between the older versions of dba_db3.c and the current release. Possibly in the future an optional 'type' argument could be allowed to be passed through dba_open() ?