
hwnd
User
Mar 19, 2013, 10:52 PM
Post #5 of 9
(176 views)
|
|
Re: [FishMonger] storing all param for later use
[In reply to]
|
Can't Post
|
|
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. 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)
|