Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Avoid SQL injection

by Corion (Patriarch)
on Jan 20, 2023 at 11:49 UTC ( [id://11149722]=note: print w/replies, xml ) Need Help??


in reply to Avoid SQL injection

Avoiding SQL injection is simple. Use DBI placeholders.

Instead of concatenating your values into your string, put ? there, and then place the values in ->execute(...).

You have structured your code around concatenating strings, so I would first replace the sqlSelect</p> with something like:

sub sqlSingleRow( $sql, @placeholders ) { my $sth = $dbh->prepare( $sql ); $sth->execute(@placeholders); # Do you really get only ever a single row back? my (@r)=$c->fetchrow(); $c->finish(); return @r; }

... and then use that routine like:

my $sql_cat = <<'SQL'; select ref_categorie from categorie_libelle_langue , libelle , langue from ref_categorie where libelle.libelle = ? AND categorie_libelle_langue.ref_libelle = libelle.id_libel +le AND categorie_libelle_langue.ref_langue = langue.id_langue +AND langue.key = ? SQL my ($cat) = sqlSingleRow($sql_cat, $category, $lang );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11149722]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found