sub save { my $self = shift; my $table = shift; my $args = shift; # this is your hash of fields and values my @place = (); my @field = (); my @value = (); # # insert into table # foreach (keys %{$args}) { push @place, '?'; push @field, $_; push @value, $args->{$_}; } my $string = qq[ insert into $table ( ] . join(' ,', @field) . qq[ ) values ( ] . join(' ,', @place) . qq[ ) ]; $self->error_to_log("$string"); my $id = $self->db_do($string , \@value ); return ($id); } sub db_do { my $self = shift; my $string = shift; my $placeholders = shift; my $id; $self->error_to_log("$string"); my $cursor = $self->dbh->prepare($string); $cursor->execute(@{ $placeholders }); if ($string =~ /^\s?insert/i) { $id = $self->dbh->{'mysql_insertid'}; $self->error_to_log("ID $id",1); } return ( $id ); }