By publishing this post I try to help people who want to get access to popular and simple database engine sqlite through perl script. I use sqlite to store e-mails statistics at small mail server in order to retrieve information about users’ mail activity like average response time, sent and received messages and etc. There is perl script that is used to get this data per every user or get summary statistics. This script is to be run by web server (I use Apache) and has name index.cgi in my case.

Here is part of it:

#!/usr/bin/perl
use DBI;
print “Content-type: text/html\n\n”;
print “<html><head><title>perl and sqlite example script</title></head><body>”;
$dbh = DBI->connect( “dbi:SQLite:dbname=/tmp/mail_data.db”,”", “”, { RaiseError => 1, AutoCommit => 0 });

my $fst = $dbh->selectall_arrayref(“SELECT min(time_1),max(time_1) FROM mail_data”);
foreach my $row (@$fst) {
my ($fst_pr,$lst_pr) = @$row;
print “oldest entry in database: “.gmtime($fst_pr).” gmt<br>newest entry in database: “.gmtime($lst_pr);
}

print “</body>”;
print “</html>”;
$dbh->disconnect;

After you load this example through any web browser (please read your web server’s manual on how to allow cgi/perl script exec, for example here), script will read sqlite database that is located at /tmp/mail_data.db and display minimal and maximal values of field time_1 from mail_data table.

In order to run this script it’s necessary to install perl, sqlite3 and perl-DBI-SQLite cpan module.

You may also be interested in:
CGI Perl scripts debugging (solve 500 Internal Server Error)

 

109 Comments

 

  1. August 30, 2012  7:31 am by abtechtes Reply

    http://www.abtechtest.com


    test and measurement equipment , spectrum analyzer, oscilloscope, network analyzer

  2. September 11, 2012  2:33 am by royaltyfreeh icons Reply

    You are mistaken. Let's discuss it. Write to me in PM, we will talk.

    P.S. Please review our icons for Windows 8

  3. September 12, 2012  5:52 pm by icon album Reply

    I recommend to you to visit a site on which there are many articles on this question.

    P.S. Please review our iconalbum.com site.

  4. September 12, 2012  6:54 pm by ikonzes Reply

    It agree, it is an amusing phrase


    P.S. Please review our ikonzes site.

  5. September 12, 2012  8:13 pm by icon-design Reply

    It is very a pity to me, that I can help nothing to you. But it is assured, that you will find the correct decision. Do not despair.


    By the way, what do you think about this icons site?

  6. September 26, 2012  4:54 pm by TopMoica Reply

    ??????????? ???????? «??????????? ?????????» ???? ??????? ? 2012 ???? ? ???????????? ????? ???????????????? ?????????? ????????, ??? ?????? ??????? ? ?????????? ?????? ??????????????? ??????????? ???????????? – ??????????? ????????, ?????????, ?????? ?? ?????, ?????????????????? ??????????, ????????????? ???????????? ?????????? ?? ?????????????????, ?????????????? ? ??.

    ??????????? ??????

Leave a reply

 

Your email address will not be published.