in reply to Re: Getting Perl Data Structures from DBI queries
in thread Getting Perl Data Structures from DBI queries
If what you are looking for is a way to store objects in a database, here is an example of one way to store an object (in this case a CGI.pm query object) in a database and then retrieve it
#!perl -w use strict; use DBI; use CGI; my $dbh = DBI->connect("DBI:DBM(RaiseError=1):mldbm=Storable"); my $sql = { drop => "DROP TABLE test" , create => "CREATE TABLE test (name VARCHAR(10), cgi_obj BLOB)" , insert => "INSERT INTO test (name,cgi_obj) VALUES (?,?)" , select => "SELECT cgi_obj FROM test WHERE name=?" }; populate( Barney => new CGI('species=dinosaur&color=purple') ); my $q = $dbh->selectrow_array( $sql->{select},{},'Barney'); my $rv = ( $q->param('color') eq 'purple' ) ? "ok" : "bad"; print "$rv!\n"; sub populate { eval { $dbh->do($sql->{drop}) }; $dbh->do( $sql->{create} ); $dbh->do( $sql->{insert},{},@_); } __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Getting Perl Data Structures from DBI queries
by helphand (Pilgrim) on Apr 22, 2004 at 04:45 UTC | |
by jZed (Prior) on Apr 22, 2004 at 04:56 UTC |