简体   繁体   中英

PERL How to connect to SQLite database

I have the following HTML + PERL code for connecting to the SQLite Database and retrieving a value, incrementing it, and updating this new value in the database. However, my code is giving an Internal Server Error when ran on browser. I'm using Apache Server. The error log tells me to check my html code but there's nothing wrong with it. Please help:

    <html>                                                                                               
    <body>
    <form action="/cgi-bin/a.pl"    method="POST">
        <input type="submit" value="Visit"/>
    </form>
    </body>
    </html>


    #!C:/Perl/bin/perl.exe

    use DBI;
    use strict;
    use CGI;

    my $cgi = CGI->new();
    my $driver   = "SQLite";
    my $database = "my.db";
    my $dsn = "DBI:$driver:db:$database";
    my $userid = "";
    my $password = "";
    my $dbh = DBI->connect($dsn, $userid, $password) or die $DBI::errstr;

    my $sth = $dbh->prepare("SELECT cnt from VISITORS");
    my $rv = $sth->execute() or die $DBI::errstr;
    my @row = $sth->fetchrow_array();
    my $nov = $row[0];
    $nov++;
    $dbh->do('UPDATE VISITORS SET NOV = ? WHERE NOV = ?', undef, $nov, $nov-1);
    $dbh->disconnect();

    print $cgi->header('text/html');
    print "No. of visitors = ". $nov . "\n";

我的错误是我没有创建表,因此无法识别表的名称,insert语句失败。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM