On 8/28/07, oryann9 <[EMAIL PROTECTED]> wrote:
snip
> Thank you for replying but since I am trying to learn
> your response did not help much. :(
> Any add'l help?
snip

#!/usr/bin/perl

use strict;
use warnings;
use DBI;

my $dbh = DBI->connect(
        'DBI:CSV:f_dir=csvdb', #the directory csvdb in the current dir
        '', #user
        '', #pass
        {
                AutoCommit => 1, #commit after ever insert, update, delete
                PrintError => 0, #don't print errors
                RaiseError => 1, #because I want to die instead
                ChopBlanks => 1, #turn "foo    ", in the db into "foo"
                FetchHashKeyName => 'NAME_lc', #use lower case keys
                csv_sep_char => ';' #use ; instead of ,
        }
) or die DBI->errstr;

unless (-f "csvdb/test") {
        $dbh->do("create table test (id int, name char(10))");
}

$dbh->do("delete from test");

my $insert = $dbh->prepare("insert into test (id, name) values (?, ?)");

$insert->execute(1, "Alice");
$insert->execute(2, "Bob");
$insert->execute(3, "Charlie");
$insert->execute(4, "Dwight");

my $sth = $dbh->prepare("select * from test order by id");
$sth->execute;
while (my $row = $sth->fetchrow_hashref) {
        print "$row->{id} is $row->{name}\n";
}
$sth->finish;

$dbh->disconnect;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to