Tie::DBI is a Perl module with tie hashes to DBI relational databases.
SYNOPSIS
use Tie::DBI;
tie %h,'Tie::DBI','mysql:test','test','id',{CLOBBER=>1};
tie %h,'Tie::DBI',{db => 'mysql:test',
table => 'test',
key => 'id',
user => 'nobody',
password => 'ghost',
CLOBBER => 1};
# fetching keys and values
@keys = keys %h;
@fields = keys %{$h{$keys[0]}};
print $h{'id1'}->{'field1'};
while (($key,$value) = each %h) {
print "Key = $key:n";
foreach (sort keys %$value) {
print "t$_ => $value->{$_}n";
}
}
# changing data
$h{'id1'}->{'field1'} = 'new value';
$h{'id1'} = { field1 => 'newer value',
field2 => 'even newer value',
field3 => "so new it's squeaky clean" };
# other functions
tied(%h)->commit;
tied(%h)->rollback;
tied(%h)->select_where('price > 1.20');
@fieldnames = tied(%h)->fields;
$dbh = tied(%h)->dbh;
This module allows you to tie Perl associative arrays (hashes) to SQL databases using the DBI interface. The tied hash is associated with a table in a local or networked database. One column becomes the hash key. Each row of the table becomes an associative array, from which individual fields can be set or retrieved.
Product's homepage
Requirements:
· Perl