in reply to Re: Problem with DBI and MySQL
in thread Problem with DBI and MySQL

FloydATC:

If you're going to use prepare then execute for a single-use query, I still advocate using placeholders. Here's why:

NOTES:

[1] Meaning that the SQL the server may precompile is known to the developer, rather than being modified by text manipulations. I realize that the resulting parse tree will be identical with proper use of quoting, #############

[2] Converting your example to use placeholders gives us:

my $name = "; DROP DATABASE mysql;"; my $sth = $dbh->prepare("INSERT INTO names (name) values (?)"); $sth->execute($name);

[3] If the driver supports it, then the server can compile the execution plan for the statement. Afterwards, no combination of quotes, semicolons, comments, etc. can make the server drop a table (or other action) not already in the execution plan.

...roboticus

Replies are listed 'Best First'.
Re^3: Problem with DBI and MySQL
by FloydATC (Deacon) on Aug 25, 2010 at 15:52 UTC
    I agree, $dbh->do() would have been much better as an example of a once-off query, and as a general rule placeholders produce code that is easier to read and debug. Where possible.

    Otherwise, use $dbh->quote().

    -- Time flies when you don't know what you're doing