The Best Cyprus Community

Skip to content


PHP Database Problem

Feel free to talk about anything that you want.

PHP Database Problem

Postby Sega » Wed Oct 10, 2007 8:36 pm

I have been killing myself over this problem and I can't find a solution. Basically I am running my PHP script locally on my home computer, I am currently on the topic of databases, but I keep getting this error:


"Fatal error: Call to undefined function dba_open() in C:\Program Files\EasyPHP 2.0b1\www\test.php on line 10"

The PHP code is as follows:


$dbh = dba_open("./data/products", "c", "gdbm") or die ("Could not open the database in question");

dba_insert ("Sonic Screwdriver", 23.20, $dbh);
dba_insert ("Tricorder", 55.55, $dbh);
dba_insert ("ORAC AI", 2200.50, $dbh);
dba_insert ("HAL 2000", 4500.00, $dbh);

dba_close($dbh);

Basically i am going through a book, so supposidly the above PHP code is correct, well why wont it run on my local computer??

Can somebody please help, I know asking for PHP help in this forum is a long shot but there must be somebody out there!
User avatar
Sega
Contributor
Contributor
 
Posts: 895
Joined: Mon Mar 05, 2007 10:21 pm

Re: PHP Database Problem

Postby Get Real! » Wed Oct 10, 2007 8:50 pm

Sega wrote:The PHP code is as follows:

$dbh = dba_open("./data/products", "c", "gdbm") or die ("Could not open the database in question");

This string looks like the file path of the database file containing the products. Do you have this file and is this path valid? (Can a file path start with a period?)

The problem with running exercises from books is that when the example needs to access the disk it can't possibly include a path name that the reader will also have so they try to indicate that you should tend to this matter... in this case with a period.

NB: I have no experience with this PHP language so I'm just using my past experience with other languages to arrive at this conclusion.
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby raymanuva » Wed Oct 10, 2007 8:56 pm

Dont u need to setup ODBC for that? And why would u want to use Access and PHP? a bit weird...
User avatar
raymanuva
Regular Contributor
Regular Contributor
 
Posts: 1102
Joined: Sun May 21, 2006 7:28 pm

Postby Sega » Wed Oct 10, 2007 9:02 pm

Basically, again, I am not such a proffesional. I think you have a point, even without your PHP experience. I thought the code as you specified was suppose to create a database. But you might have a point. The book did not elaborate on this issue. But I can't seem to find a solution, even online help is scarce, I think I might have a problem locally. I am not certain however.
User avatar
Sega
Contributor
Contributor
 
Posts: 895
Joined: Mon Mar 05, 2007 10:21 pm

Postby Sega » Wed Oct 10, 2007 9:05 pm

[quote="raymanuva"]Dont u need to setup ODBC for that? And why would u want to use Access and PHP? a bit weird...[/quote]

I am basically going through a book and this is how they chose to do things.
User avatar
Sega
Contributor
Contributor
 
Posts: 895
Joined: Mon Mar 05, 2007 10:21 pm

Postby Get Real! » Wed Oct 10, 2007 9:12 pm

Sega wrote:Basically, again, I am not such a proffesional. I think you have a point, even without your PHP experience. I thought the code as you specified was suppose to create a database. But you might have a point. The book did not elaborate on this issue. But I can't seem to find a solution, even online help is scarce, I think I might have a problem locally. I am not certain however.

The function "dba_open"...

$dbh = dba_open("./data/products", "c", "gdbm")

...appears to accept three parameters:

1. File path
2. Drive
3. File name

...so putting it all together yields:

C:\data\products\gdbm.??? (<--- Insert file EXTENSION expected by PHP)

But you seemingly don't have this file.
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby phoenix » Wed Oct 10, 2007 9:16 pm

Mmmm . . . . nice thread 8)
User avatar
phoenix
Main Contributor
Main Contributor
 
Posts: 3452
Joined: Wed Aug 22, 2007 2:47 pm
Location: Free From Forum

Postby morhekil » Wed Oct 10, 2007 9:16 pm

Folks, can you read English? ;) The error message is very specific: "Fatal error: Call to undefined function dba_open()". That means that dba-related functions are not enabled in your PHP installation, and they're not enabled by default. Find file named like php_dba.dll in your php, copy it somewhere to your system PATH (like C:\Windows, for example) and uncomment "extension=php_dba.dll" line in your php.ini. Then restart your webserver and you'll get your functions.
morhekil
Member
Member
 
Posts: 66
Joined: Sun Jul 03, 2005 4:31 pm
Location: Nicosia

Postby Sega » Wed Oct 10, 2007 9:27 pm

I have previously uncommented the "extension=php_dba.dll", by removing the semi-colon, but the error message changes to:

"Warning: dba_open(./data/products,c) [function.dba-open]: No such handler: gdbm in C:\Program Files\EasyPHP 2.0b1\www\test.php on line 10
Could not open the database in question"

I also copied the file specifically named "php_dba.dll", to c:\windows and I restarted the server. The problem however still persists.
User avatar
Sega
Contributor
Contributor
 
Posts: 895
Joined: Mon Mar 05, 2007 10:21 pm

Postby Get Real! » Wed Oct 10, 2007 9:46 pm

Sega wrote:"Warning: dba_open(./data/products,c) [function.dba-open]: No such handler: gdbm in C:\Program Files\EasyPHP 2.0b1\www\test.php on line 10
Could not open the database in question"

There's what it appears to be looking for.
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Next

Return to General Chat

Who is online

Users browsing this forum: No registered users and 0 guests