in reply to Re^5: DBI do() SQL injection
in thread DBI do() SQL injection

You can always fix that by wrapping the value into a quote
And is there any advantage to using quote instead of placeholders?
sub run_do_with_placeholders($dbh, $id, $name) { $dbh->do(qq{ INSERT INTO customers (id,name) VALUES(?, ?)}, undef, $id, $name); }
There are a few places (table and column names, mostly) where you're required to use quote instead of placeholders, but, IMO, you should always use placeholders for data values where possible and never rely on quoting unless you absolutely have to.

Replies are listed 'Best First'.
Re^7: DBI do() SQL injection
by choroba (Cardinal) on Oct 20, 2023 at 17:38 UTC
    > There are a few places (table and column names, mostly) where you're required to use quote instead of placeholders

    No, please don't. Use quote_identifier for table and column names.

    quote is useful when placeholders can't be used, e.g. you're sending the SQL statement to a function that doesn't accept any other arguments and you can't change it; but generally placeholders are easier and cleaner.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      No, please don't. Use quote_identifier for table and column names.
      Whoops! Good catch, and thanks for the correction!