[ABE.pm] Storable.pm and MySQL - Example

Faber J. Fedor faber at linuxnj.com
Mon Mar 19 16:53:20 PDT 2007


This program shows the problem.  Be sure to add your own MySQL parms
near the top.

Step through this and look at the table after you INSERT the data and
look at $frozen.  They are not the same value.

Why $melted_popsicle is undef at the exit(0) is another problem.

<----------------------------< cut here >--------------------------->

#!/usr/bin/perl

use strict;
use warnings;
use DBI;
use Storable qw(freeze thaw) ;

## Set these to your settings ##

my $db = ;
my $dbUsername =  ;
my $dbPasswd = ;

## end of configuration

my $dbh = DBI->connect ('DBI:mysql:'.$db, $dbUsername, $dbPasswd );

my $stmt = 'drop table if exists storabletest';
$dbh->do($stmt);

$stmt = 'create table storabletest (realdate date, myblob blob)';
$dbh->do($stmt);



my %data = { average => 10,
             myarray => [ ['ABC', 123], ['DEF', 345]],
             total => 'cereal' 
        };


my $frozen = freeze \%data;

$stmt = 'insert into storabletest (realdate, myblob) values (\'20011001\',\''. $frozen.'\')' ;
$dbh->do($stmt);




$stmt = 'select * From storabletest where realdate = 20011001';

my @popsicle = $dbh->selectall_arrayref($stmt);

my $melted_popsicle = thaw $popsicle[1];

exit(0);



<----------------------------< cut here >--------------------------->


-- 
 
Regards,
 
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701

http://www.linuxnj.com





More information about the ABE-pm mailing list