Help us understand the problem. What is going on with this article?


More than 3 years have passed since last update.

・SQLインジェクションのリスクを避けたい。 :spy_tone5:



&updateStatus($dbh, @list);

sub updateStatus{

   #関数を呼ぶとき渡すパラメター。 $dbh:DB接続の設定、@list:取得のリスト配列
   my($dbh, @list)=@_;

    my $cnt=@list;


    my @mark;

    for(my $i=1; $i<=$cnt; $i++){
        push(@mark, "?");

    my $markString=join(',',@mark);

    my $sql1=qq[
              UPDATE table1
              SET status = '1'
              WHERE id in ($markString)

    my $sth = $dbh->prepare($sql1)|| die "$DBI::errstr";


    for(my $j=0; $j<$cnt; $j++){
        my $k=$j+1;
        $sth->bind_param($k, $list[$j]);

    $sth->execute || die "$DBI::errstr";

   //AutoCommit がオフ(0)の時

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away