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!


In reply to cgi can't write to sqlite database by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.