#!/usr/bin/perl
use warnings;
use strict;
use DBI;

my $dbFile = 'test.db';
my $dbUsername = '';
my $dbPassword = '';
# 
my $dbh = DBI->connect("DBI:SQLite:dbname=$dbFile", $dbUsername, $dbPassword);

my $table = 'test';
my $sth = $dbh->do("CREATE TABLE IF NOT EXISTS $table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER);");

$sth = $dbh->prepare("INSERT INTO $table (name, age) VALUES (?,?);");
$sth->execute('Charlie', 13);
$sth->execute('Steve', 34);
$sth->execute('Mary', 34);
$dbh->commit() or die $DBI::errstr;

$sth = $dbh->prepare("SELECT * FROM $table WHERE age=?;");
$sth->execute(34);
while(my @row = $sth->fetchrow_array()){
    my ($id, $name, $age) = @row;
    print "$id | $name | $age\n";
}

$sth = $dbh->prepare("SELECT * FROM $table WHERE name=?;");
$sth->execute('Charlie');
my ($id, $name, $age);
$sth->bind_columns(\$id, \$name, \$age);
while($sth->fetch()){
    print "$id | $name | $age\n";
}

$sth = $dbh->prepare("SELECT * FROM $table WHERE name=?;");
$sth->execute('Steve');
while(my $row = $sth->fetchrow_hashref()){
    print "$row->{id} | $row->{name} | $row->{age}\n";
}

my $rc = $dbh->disconnect  or warn $dbh->errstr;
