Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!c:\perl\bin\perl use strict; use warnings; use CGI; use DBI; my $q = new CGI; if($q->param("addrecord")){ my %cols = ( servicename => "Name", description => "description", url => "url", help => "helpdesk", group => "grp", hbi => "hbi", riskregister => "register", serviceman => "service_manager", servemail => "man_email", servtel => "man_phone", deputy => "deputy_manager", depemail => "dep_email", deptel => "dep_phone" ); my $keystring = (); my $valuestring = (); my $db = DBI->connect('foo', 'bar', 'baz') or die "Can't connect"; foreach ( qw/ servicename description url help group hbi riskregis +ter serviceman servemail servtel deputy depemail deptel /) { if ({$_}) { $keystring .= $cols{$_} .","; $valuestring .= $db->quote({$_}) .","; } } #remove last comma $keystring =~ s/,$//; $valuestring =~ s/,$//; my $statement = qq( INSERT INTO service_metrics ($keystring) VALUES ($valuestring) ); my $sth = $db->prepare($statement); if (! $sth) { die(sprintf('[FATAL] Could not prepare statement: %s\n\n + ERRSTR: %s\n', $db->errstr())); } $sth->execute(); if (! $sth) { die(sprintf('[FATAL] Could not execute statement: %s\n\n + ERRSTR: %s\n', $db->errstr())); } $sth->finish; $db->disconnect(); } print $q->header(); print $q->start_html(-title=>'New Service'); print "You have added a service";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Receinving hash where expecting a string
by Joost (Canon) on Aug 15, 2007 at 12:34 UTC | |
|
Re: Receinving hash where expecting a string
by moritz (Cardinal) on Aug 15, 2007 at 13:36 UTC | |
by Anonymous Monk on Aug 15, 2007 at 13:41 UTC | |
|
Re: Receinving hash where expecting a string
by FunkyMonk (Bishop) on Aug 15, 2007 at 12:36 UTC |