I am trying to write a script to update a mySQL table. I create a SELECT cmd with placeholders; I copy the updated field values into a bind array. However, one of the fields include a comma in the value. So the DBI::EXECUTE cmd thinks there is one too many values
Results in the following ...#!/usr/bin/perl -w my $dbh = open_admin(); my $table ="test"; my $year = "2018"; my %updates = (); my $k =7749; my $new = q["Boop, Betty"]; ## 'Boop, Betty'; $updates{$k}{name} = $new; $updates{$k}{age} = 33; foreach my $id ( keys %updates ){ my $update = ""; $update .= "UPDATE $table SET "; my @binds = (); my $i = 0; foreach my $fn ( keys %{$updates{$id}} ) { $update .= " $fn=?, "; $binds[$i] = $updates{$id}{$fn}; $i++; } push @binds, $k; $update .= "WHERE course_id =? AND year=$year"; my $xbinds = join ", ", @binds; print "update [$udate]\n"; print "binds --> {$xbinds }\n"; my $sth = $dbh->prepare($update); $sth->execute(@binds, $id); } exit;
-bash-4.1$ ./bbtest update [UPDATE test SET name=?, age=?, WHERE course_id=? AND year=2 +018] binds --> {"Boop, Betty", 33, 7749 } DBD::mysql::st execute failed: called with 4 bind variables when 3 are + needed at ./bbtest line 36.
In reply to DBI UPDATE w comma in field value by FryingFinn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |