Is there an equivalent of PHP's mysql_real_escape_string() for Perl's DBI?

前端 未结 5 594
-上瘾入骨i
-上瘾入骨i 2020-12-11 16:56

Could some tell me if there is a function which works the same as PHP\'s mysql_real_escape_string() for Perl from the DBI module?

5条回答
  •  孤街浪徒
    2020-12-11 17:24

    From http://www.stonehenge.com/merlyn/UnixReview/col58.html :

      use SQL::Abstract;
      ... 
      my $sqa = SQL::Abstract->new;
      my ($owner, $account_type) = @_; # from inputs
      my ($sql, @bind) = $sqa->select('account_data', # table
                                      [qw(account_id balance)], # fields
                                      {
                                        account_owner => $owner,
                                        account_type => $account_type
                                      }, # "where"
                                     );
      my $sth = $dbh->prepare_cached($sql); # reuse SQL if we can
      $sth->execute(@bind); # execute it for this query
    

提交回复
热议问题