# Collection of code snippets by Arne Vajhøj 
# posted to eksperten.dk, usenet and other places (2002-now) 
use DBI;
# connect
my $con = DBI->connect('DBI:mysql:host=localhost:database=Test','','') or die DBI->errstr;
# display all rows
my $stmt = $con->prepare('SELECT * FROM t1') or die $con->errstr;
$stmt->execute;
while(@row = $stmt->fetchrow_array()) {
    my $f1 = $row[0];
    my $f2 = $row[1];
    print "$f1 $f2\n";
}
# insert new row
my $stmt = $con->prepare('INSERT INTO t1 VALUES(?,?)') or die $con->errstr;
$stmt->execute(6,'FFFFFF');
# display all rows again
my $stmt = $con->prepare('SELECT * FROM t1') or die $con->errstr;
$stmt->execute;
while(@row = $stmt->fetchrow_array()) {
    my $f1 = $row[0];
    my $f2 = $row[1];
    print "$f1 $f2\n";
}
# disconnect
$con->disconnect;
