Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Getting mysql data into gd

by shanta (Novice)
on Sep 03, 2017 at 19:45 UTC ( #1198636=note: print w/replies, xml ) Need Help??


in reply to Re^3: Getting mysql data into gd
in thread Getting mysql data into gd

thanks for the great response

I can see the drift of it. How would this prevent drop table my_table example? It could be in the variable being sent anyway.

can I send?

$ST->execute(text, text2, moretext);

Thanks for the help

Replies are listed 'Best First'.
Re^5: Getting mysql data into gd
by roboticus (Chancellor) on Sep 04, 2017 at 00:02 UTC

    shanta:

    DBI has all the SQL quoting rules handled, so using placeholders would turn it into:

    select foo, bar from my_table where col < '''drop table my_table; --' or (col > 'def_val' and col3 < fgh_val)

    Here, the drop table command isn't exposed as an SQL statement, it's just a column value checked in the where clause. If you were really careful all the time and made sure you handled all the quoting and comments properly, you could ignore placeholders and not run into trouble. But I don't know anyone careful enough to *always* get it right. Instead DBI does it for you, and you don't need to remember the rules for whichever database you use.

    Some database back ends understand placeholders and can give you a performance boost when you use them, so using placeholders gives you the chance to squeeze a little more performance out of your database for the ones that understand it (such as Sybase, MSSQL, Oracle, Pg).

    For example, suppose you wanted to do something like this:

    insert into my_table select ? as foo, ? as bar, c.id as product_id, d.price as product_pric +e from my_stuff c where c.name=? join friend_prices d where d.name=? and c.class=d.class

    When the SQL back-end parses this, it writes a little program to do the table joins and lookups for the insert. If you just substitute the values into the SQL and prepare then execute it each time, it has to repeat all the work to generate the query plan each time. But if you use placeholders, it only needs to do generate the query plan once, because you can re-use the statement:

    my $ST = db->prepare(q{ insert into my_table select ? as foo, ? as bar, c.id as product_id, d.price as product_ +price from my_stuff c where c.name=? join friend_prices d where d.name=? and c.class=d.class }); $ST->execute(123, 456, 'Mouse', 'Joe'); $ST->execute(149, 357, 'Mousepad', 'Joe');

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2021-01-21 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?