#!/usr/bin/perl use strict; use warnings; use DBI; my $username = 'xxxxxx'; my $password = 'xxxxxx'; my $host = 'localhost'; my $database = 'xxxxxx_innoTest'; my $tableName = 'members'; my $data_source = "DBI:mysql:database=$database;host=$host"; # Overriding for local testing with SQLite. my $db_file = 'pm790190.sqlite'; sub sqlite { system( sqlite3 => '-line', $db_file, @_ )==0 or warn; } { unlink $db_file if -e $db_file; sqlite(<<'END_OF_SQL'); CREATE TABLE members ( nameLogin char(50), password char( 8), nameFirst char(20), nameLast char(20), email char(30) ); END_OF_SQL $data_source = "dbi:SQLite:dbname=$db_file"; } my %memberRecord = ( nameLogin => 'testloginname; DROP TABLE members;', password => 'testpwd', nameFirst => 'testfirstname', nameLast => 'testlastname', email => 'testemail@mycompany.com', ); my @column_names = sort keys %memberRecord; my @column_values = map { $memberRecord{$_} } @column_names; my @placeholders = map { '?' } @column_names; my $column_name_list = join ', ', @column_names; my $placeholder_list = join ', ', @placeholders; my $sqlStatement = <<"END_OF_SQL"; INSERT INTO $tableName ($column_name_list) VALUES ($placeholder_list) END_OF_SQL my $dbh = DBI->connect( $data_source, $username, $password ) or die $DBI::errstr; my $sth = $dbh->prepare( $sqlStatement ) or die $dbh->errstr; $sth->execute(@column_values) or die $dbh->errstr; $sth->finish(); undef $sth; $dbh->disconnect() or warn "Disconnection failed: $DBI::errstr\n"; # Checking results of local testing with SQLite. sqlite('SELECT * FROM members');