Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
O monks,
I have a little embedded database app that is purely for my own use, implemented as a cgi. I'm running apache on ubuntu, and the database is a sqlite file, accessed through the DBI package. I got the whole thing working great for read access. However, I can't seem to set it up so that apache can write to the sqlite file. Here's the initial version of my code that runs when I fill in a form and submit it:
#!/usr/bin/perl # requires DBD::SQLite use DBI; use strict; print html_header(); my $db = "/home/bcrowell/Documents/writing/selling_fiction/stories.sql +t"; my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",{ RaiseError => 1 +, AutoCommit => 1 }) or err("connecting"); print html_footer(); local $/; my $stuff = <>; my %inputs; foreach my $input(split(/&/,$stuff)) { $input =~ /(.*)=(.*)/; $inputs{$1} = $2; } # magazine, story, date my $magazine = $inputs{'magazine'}; # key my $story = $inputs{'story'}; my $date = $inputs{'date'}; print "$magazine, $story, $date\n"; my $insert_statement = <<INSERT; insert into submissions (magazine,story,date_submitted) values ($mag +azine,$story,$date) INSERT $dbh->do($insert_statement); $dbh->disconnect;
Here's the message that shows up in my apache error log:
DBD::SQLite::db do failed: unable to open database file(14) at dbdimp. +c line 403 at /usr/lib/cgi-bin/record_submission.cgi line 33, <> chun +k 1. DBD::SQLite::db do failed: unable to open database file(14) at dbdimp. +c line 403 at /usr/lib/cgi-bin/record_submission.cgi line 33, <> chun +k 1.
The line it's referring to is the $dbh->do(...).
I've tried setting the file to be globally writeable. I've tried moving the file out of my home directory and into the cgi-bin directory. Neither of those things seemed to help. I'm guessing that this is something related to security that apache is doing. This is just running on my desktop machine, however, and I'm behind my router's built-in firewall, so I'm not worried about the security of the script.
Any suggestions would be much appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: cgi can't write to sqlite database
by moritz (Cardinal) on Jul 03, 2008 at 21:06 UTC | |
by bcrowell2 (Friar) on Jul 03, 2008 at 21:31 UTC | |
by Anonymous Monk on May 10, 2019 at 08:09 UTC |