Home » Programming » Perl » Access To Sqlite3 Database Through Perl Script Example

Access to sqlite3 database through perl (script example)

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)

SHARE:
Photo of author
Author
My name is Stefan, I'm the admin of LinuxScrew. I am a full-time Linux/Unix sysadmin, a hobby Python programmer, and a part-time blogger. I post useful guides, tips, and tutorials on common Linux and Programming issues. Feel free to reach out in the comment section.

20 thoughts on “Access to sqlite3 database through perl (script example)”

  1. He put his eye to the hole. He just managed to spy some people sitting in deckchairs chanting, before a finger came out of nowhere and poked him in the eye. As he staggered back, the people started chanting, "Fourteen, fourteen, fourteen…"

    Reply
  2. We offer foreign companies the financial and consulting services:
    opening a representative office in Russia
    Marketing Research,
    tax optimization,
    withdrawals abroad
    kickbacks payer.

    Reply
  3. ???????? ????????? ?? 8 ????? 155 ????? ? ??? ?? ?? 43 ?????? 500 ???????? ? ????? ??????? ????????? ?????? ??????? ????? ????????.
    ???????? ????? ??????? ? ??????? 23 ????? ????? ???????.
    ????? 243 ?????? ?? ????????.
    ??? ???. 89266853242 ICQ 568113539 [email protected] zf 210j h ev

    Reply
  4. ???????? ??? ????? ????? ?????????? ?? 5 ????? 300 ????? ? ??? ?? ?? 42 ?????? 500 ???????? ? ????? ?????? ? ??????? ????? ?? ?????? ??????? ????? ???????????. ???????? ????? ??????? ? ??????? 27 ????? ????? ???????.
    ????? 228 ?????? ?? ????????. ??? ???. 89266853242 ICQ 568113539 [email protected] gk 287r r lz

    Reply
  5. ???????? ??? ????? ?? 8 ????? 155 ????? ?????????? ? ??? ?? ?? 50 ????? ???????? ???????? ? ????? ??????? ? ??????? ????? ?? ?????? ???????? ???????????. ???????? ????? ??????? ? ??????? 25 ????? ????? ??????.
    ????? 229 ?????? ?? ????????. ??? ???. 89266853242 ICQ 568113539 [email protected] iz 079u v lb

    Reply
  6. ???????? ???????? ?????????? ?? 7 ????? 300 ????? ?????????? ? ??? ?? ?? 45 ?????? 500 ???????? ? ????? ??????? ????? ?? ?????? ??????? ????? ????????. ???????? ????? ??????? ? ??????? 18 ????? ????? ??????.
    ????? 248 ?????? ?? ????????. ??? ???. 89266853242 ICQ 568113539 [email protected] bu 300f d dl

    Reply
  7. ???????? ????????? ?? 8 ?????? 999 ????? ? ??? ??? ?? 43 ?????? ???????? ???????? ? ????? ?????? ? ??????? ????? ?? ?????? ???????? ????????????? ????????.
    ???????? ????? ??????? ? ??????? 30 ????? ????? ??????.
    ????? 235 ?????? ?? ????????.
    ??? ???. 89266853242 ICQ 568113539 [email protected] st 675l n ng

    Reply
  8. ?? ???????? ???????? ?? 5 ????? 300 ????? ?????????? ? ??? ?? ?? 44 ?????? ???????? ???????? ? ????? ???????????? ????? ?? ?????? ??????? ????? ????????????? ????????.
    ???????? ????? ??????? ? ??????? 28 ????? ????? ??????.
    ????? 213 ?????? ?? ????????.
    ??? ???. 89266853242 ICQ 568113539 [email protected] yq 907v m jz

    Reply
  9. ???????? ???????? ?????????? ?? 8 ?????? 800 ????? ? ??? ?? ?? 43 ?????? 500 ???????? ? ????? ???????????? ??????? ?????? ?????? ???????????.
    ???????? ????? ??????? ? ???????? 17 ????? ????? ??????.
    ????? 222 ?????? ?? ????????.
    ??? ???. 89266853242 ICQ 568113539 [email protected] dq 779f z nf

    Reply
  10. fw 707r r mo ?? ???????? ???????? ?? 8 ????? 340 ????? ?????????? ? ??? ?? ?? 45 ?????? 500 ???????? ? ????? ??????? ????????? ?????? ???????? ???????????.

    ???????? ????? ??????? ? ??????? 24 ????? ????? ??????.

    ????? 218 ?????? ?? ????????.

    ??? ???. 89266853242 ICQ 568113539 ?????: [email protected] xt 930k h ma

    Reply
  11. ?????? ????????? ?????????????????????? ?????? ?????? ??????? ? ???????????????????? ? ?????? ??????????????? ??? ????? ???????? ??? ????????? ? ?????????????? ??????? ??? ??????????????? ????????????.?????? ?.????? ??? ????? ????????? ??????? ??? ???????????? ??? ????????? ?? ???????? ???????????????? ????? ????????????? ??? ???????? ??????????? ? ????????????????????????? ??????????? ?????? ? ???????????? ??? ?????????? ?????????? ???????? ???????? ??? ????? 159 ?? ? ???? 54????? ???????? ????????????????????? ???????? ? ??????????? ?????????????????????? ????? ??? ???????? ?????????????? ????????? ???????? ??? ??? ??????? ????? ?? ?????????

    Reply
  12. I can not participate now in discussion – there is no free time. uBt I will be released – I will necessarily write that I think.

    Reply

Leave a Comment