I am trying to insert multiple values to the same field using a single query. Are there any mistakes in the following code?
my $dbh = DBI->connect("DBI:mysql:accounting:localhost", 'username', 'password',
{RaiseError => 1});
my @id = [1,18,976,90];
my @name = ['ss','dc','ws','rd'];
my @data = ([@id],[@name]);
my $ab = $dbh->prepare("insert into table (id,name) values (?,?)";);
for my $datam (@data) {
$ab->execute(@$datam);
}
$ab->finish();
I am getting the following error: DBI::st=HASH(0*a16f774) for prepare statement. What could be causing this?
Can’t really answer your question since you didn’t actually give the error, but I have spotted a problem with your code. You’re doing
when you obviously want to do
Fix: