Jump to content

Unable to create a dba database


amelio

Recommended Posts

Hi,

 

I’m learning php, studying a chapter on dba. When I try to create a simple db, the db file is being created but I’m not able to access it with dba commands, the error I get is…

 

Warning: dba_open(c:/test.db,c) [function.dba-open]: Driver initialization failed for handler: db3: 
Permission denied in C:\ listing12.2.php on line 39

 

My book uses the gdbm dbm, it says it is commonly available. However when I check my wampserver2 setup I only have the following dbm’s available to me…

 

array(5) { [0]=> string(3) "cdb" [1]=> string( "cdb_make" [2]=> string(3) "db3" 
[3]=> string(7) "inifile" [4]=> string( "flatfile" }

 

Searching, I noticed that db3 seems to be in common use so I try that first with the above result, I also get the error when I use ‘cdb’ or ‘cdb_make’

 

I succesfully created a database using ‘flatfile’ but my textbook explains that this dbm is for backwards compatability and is discouraged. I guess my success with this dbm at least proves that I have the correct permissions.

 

I am running wampserver2 (php 5.2.6, apache 2.28). If you could help me I would be very grateful.  Here is the code in full...

 

<?php
$dbh = dba_open("c:/test.db", "c", "db3") 
		or die( "Could not open database" );

dba_replace( "product_01", 25.20, $dbh );
dba_replace( "product_02", 56.50, $dbh );
dba_replace( "product_03", 73.50, $dbh );
dba_replace( "product_04", 19.50, $dbh );

?>

<table >
<tr>
<td>product</td>
<td>price</td>
</tr>

<?php

$key = dba_firstkey( $dbh );
while ( $key != false ) {
    $value = dba_fetch( $key, $dbh);
    print "<tr><td> $key </td>";
    print "<td> \$".sprintf( "%01.2f", $value )."</td></tr>";
    $key = dba_nextkey( $dbh);
}

dba_close( $dbh );

?>
</table>

Link to comment
https://forums.phpfreaks.com/topic/167607-unable-to-create-a-dba-database/
Share on other sites

I don't really know what is wrong, but I will say that in my experience, stay away from DBA. Once you do get it working, you can't really move it. I work in an environment where my project could move between systems, and not all of them supported the same db types.

 

If you want a database in a file, use SQLite

Thanks rhodesa,

 

I did wonder if it was worth getting in too deep learning dba as most people seem to go with mysql. I notice SQLite is bundled with wamp.

 

On the other hand dba seems a very good solution for a site that requires minimal database functionality. I would still like to be able to get it to work so it's there if I need it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.