my %TABLES = ( # Hash identifying one database
'users' => [ # Hash keys are the database's tables
'username',
'password', # Columns of the table in an array
'first_name',
'email_address',
'rating'
]
);
####
$handle->insert (
-table => "users",
-primary_key => "username",
-values => {
username => "mt2k",
first_name => "Nathan",
email_address => 'email@example.net',
password => crypt("password", $salt),
rating => 10
}
);
##
##
sub insert {
my ($self, %q) = @_;
# Set up placeholders
my $ph = join ', ', ('?') x values %{$q{'-values'}};
# Prepare the query for the database
my $sth = $self->{DB}->prepare(
"INSERT INTO $q{'-table'} VALUES($ph)"
);
# This is the line that causes problems. Read below for more.
$sth->execute(values %{$q{'-values'}});