Hi,
I'm trying to insert a long concatenated string from a hash of hashes into
an sql db. I have not had much luck?
Whats the best manner to do this?
sub mysend {
#send the data to the db
my($DMConcat);
my($ToConcat);
$dbh = DBI->connect("DBI:mysql:en_us:xena", "", "");
$q1 = $dbh->prepare("INSERT INTO corpus_appstats SET ?");
$q2 = $dbh->prepare("INSERT INTO ctxt_appstats SET ?");
$Toconcat .="corpus_id =".$corp;
$Toconcat .=", datetime_start=$dates";
$Toconcat .=", datetime_end=$dateend";
foreach $Module (keys %stats){
foreach $DM (keys %{ $stats {$Module}}){
foreach $type (keys %{$stats {$Module}{$DM}} ){
foreach $rc (keys %{$stats {$Module}{$DM}{$type}}){
if ($Module eq "Module") {
if (length $rc > 0){
$q3 = $dbh->prepare ("select dm_id from dm where dm_name
=? and
dm_type =? and rc_name = ?");
$q3->execute($DM, $type, $rc);
$dm_id = $q3->fetchrow_array();
print $dm_id, "after search \n";
$DMconcat .="corpus_id=$corp";
$DMconcat .=", dm_id=$dm_id";
$DMconcat .=", datetime_start=$dates";
$DMconcat .=", datetime_end=$dateend";}
}
foreach $feild (keys %{$stats{$Module}{$DM}{$type}{$rc}}){
if ($Module eq "Total") {
$Toconcat .=", $feild
=$stats{$Module}{$DM}{$type}{$rc}{$feild}"; }
if ($Module eq "Module") {
if (length $rc > 0){
$DMconcat .=",
$feild=$stats{$Module}{$DM}{$type}{$rc}{$feild}";}
else{
$Modconcat.=",
$feild=$stats{$Module}{$DM}{$type}{$rc}{$feild}";
}
}
}
}
chomp ($DMconcat);
$DMconcat .= $Modconcat;
print $DMconcat, "\n";
$q2->execute($DMconcat);
undef $DMconcat;
}
undef $Modconcat;
}
}
chomp ($Toconcat);
print $Toconcat, "\n";
$q1->execute($Toconcat);
$q1->finish ();
$q2->finish ();
$q3->finish ();
$dbh->disconnect();
undef $Toconcat;
}