CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [FishMonger] storing all param for later use: Edit Log



hwnd
User

Mar 19, 2013, 10:52 PM


Views: 692
Re: [FishMonger] storing all param for later use

My real goal is trying to use object, classes, methods to insert, remove, ... with SQL query. At first I was asking about gathering all params into a hash to store for later use which I did simplify how easy that was. Now i'm having trouble working with this class, method. It's not running through the process.


Code
   

my $dbh = hwnd->new('DBI info', '******', '******') or die $DBI::errstr;

$dbh->insert("
tablename", ['col1', 'col2', 'col3'],

['2013-03-20', '
Test', 'blah']

);

# stuff in package module


sub new {

my $class = shift;

my $self = {};

bless $self, ref( $class ) || $class;

$self->{dbh} = DBI->connect( @_ );

return $self;

}



sub insert {

my $self = shift;

my($tbl, $col, $val) = @_;

my $new_tbl = $self->{dbh}->quote($tbl);

my @new_col = map { $self->{dbh}->quote($_) } @$col;

my @placers = map { "?" } @new_col;

my $query = qq(

INSERT INTO $new_tbl

( @{[ join(', ', @new_col) ]} )

VALUES ( @{[ join(', ', @placers ]} )

);

return $self->{dbh}->do($query, undef, @$val);

}



(This post was edited by hwnd on Mar 19, 2013, 11:14 PM)


Edit Log:
Post edited by hwnd (User) on Mar 19, 2013, 11:14 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives