Current location: Hot Scripts Forums » Programming Languages » Perl » dbmopen


dbmopen

Reply
  #1 (permalink)  
Old 12-04-03, 05:19 PM
dcass dcass is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
dbmopen

i am trying to use dbmopen with a simple database. it works no problem if i use from a command prompt, but when running from web page. i do not get any errors back in the browser, but the file is never created. if i create first, it is never updated. i also tried using tie( ) instead of dbmopen. my system is using perl 5.8.0 and apache 2.0.

any suggestions?

here is code:

with dbmopen( ):

my %accounts = (1=>"Books", 2=>"Car_Repair", 3=>"Clothes",4=>"Food",5=>"Movie_Rental");
my $account = param('account');
my $dollars = param('dollars');
my $cents = param('cents');
my $account_to_modify = $accounts{$account};
my $amount_to_add = $dollars + ($cents/100);
dbmopen (my %expenses, "expense_fileb", 0644);
if ($expenses{$account_to_modify}) {
$expenses{$account_to_modify} = $expenses{$account_to_modify} + $amount_to_add;
}
else {
$expenses{$account_to_modify} = $amount_to_add;
}
dbmclose (%expenses);

with tie( ):

my %accounts = (1=>"Books", 2=>"Car_Repair", 3=>"Clothes",4=>"Food",5=>"Movie_Rental");
my $account = param('account');
my $dollars = param('dollars');
my $cents = param('cents');
my $account_to_modify = $accounts{$account};
my $amount_to_add = $dollars + ($cents/100);
tie (my %expenses,'DB_File', "expense_fileb");
if ($expenses{$account_to_modify}) {
$expenses{$account_to_modify} = $expenses{$account_to_modify} + $amount_to_add;
}
else {
$expenses{$account_to_modify} = $amount_to_add;
}
untie (%expenses);
Reply With Quote
  #2 (permalink)  
Old 12-04-03, 07:42 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Check out the pod on this function: http://www.perldoc.com/perl5.8.0/pod/func/dbmopen.html

It looks like the tie function is taking it's place. But to get you going, place an or die $!; after your dbmopen statement to see why it's failing. Run it and then check your error log.

~Charlie
Reply With Quote
  #3 (permalink)  
Old 12-04-03, 08:50 PM
dcass dcass is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
i had seen where dbmopen was being phased out, but was getting same results with tie. with the or die $! i get the following in the httpd error log:

[Thu Dec 04 21:39:39 2003] [error] [client 127.0.0.1] Premature end of script headers: ex5.8b_update.cgi, referer: http://127.0.0.1/cgi-bin/ex5.8b.cgi?whattodo=1
[Thu Dec 04 21:39:39 2003] [error] [client 127.0.0.1] Error Permission denied at /var/www/cgi-bin/ex5.8b_update.cgi line 16., referer: http://127.0.0.1/cgi-bin/ex5.8b.cgi?whattodo=1

am i missing some permission settings in apache? it works fine if i just run from command prompt.
Reply With Quote
  #4 (permalink)  
Old 12-04-03, 09:30 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah, it does look like a permissions problem. If your Apache is not running with suEXEC enabled, the script will be trying to open the file as the same user that Apache runs as (most likely the 'nobody' user) and that user doesn't have permissions enough to open the file. Or you are trying to open the wrong file.

Start by checking the permission on the file. Try 777 and then work backwards. If that doesn't work, try using the full path to the file in the dbmopen command. One of those should take care of it.

~Charlie
Reply With Quote
  #5 (permalink)  
Old 12-05-03, 08:43 PM
dcass dcass is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ok

finally got it working. created a different directory and chmod with 777. originally had the file in cgi-bin dir. will play with to see if will take less than a 777, but am happy for now. this things been driving me crazy.

thanks for help.
Reply With Quote
  #6 (permalink)  
Old 12-05-03, 08:51 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Awesome

Quote:
Originally Posted by dcass
thanks for help.
No problem.

~Charlie
Reply With Quote
  #7 (permalink)  
Old 04-27-04, 04:41 PM
bigjoe11a bigjoe11a is offline
New Member
 
Join Date: Apr 2004
Location: North Canton, Ohio USA
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dbmopen

I'm looking for a way to use the dbmopen command.

Heres what I'm trying to do


%cat_list=('Cars','0','Trucks','0','Other','0',);

I'm trying to setup a gategory list in a database

Can some one please give me some samples on how to set this up.
and how to read,write, and change the information.

The first one say Cars and the total listing = 0. I need to know how to do this
can any one help.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 04:47 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.