Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

RE: Answer: variables inside SQL statements

by johannz (Hermit)
on Oct 11, 2000 at 01:27 UTC ( [id://36137]=note: print w/replies, xml ) Need Help??


in reply to Re: variables inside SQL statements
in thread variables inside SQL statements

The danger with this approach is it is up to the developer to ensure that the interpolated string is a valid SQL command. This is particularly dangerous when the valid you wish to store contains single quotes since it the escape mechanism is Database-dependent. It is far simpler to use DBI and the '?' (question mark) syntax to specify variable substitution at execution time. This method will take care of escaping any required data for you.?

my $path = '/path/to/this'; my $sql = 'INSERT INTO table SET ( path ) VALUES ( ? )'; my $STH = $DBH->prepare($sql); $STH->execute($path);

Replies are listed 'Best First'.
RE: RE: Answer: variables inside SQL statements
by cwest (Friar) on Oct 11, 2000 at 08:19 UTC
    I would have been happy to offer that answer but I was given no sound proof that the asker was using DBD.

    Update:I hope that -- was for a sound reason. There wasn't even evidence that the user was using a database that DBI can connect to.

    --
    Casey
       I am a superhero.
    

Log In?
Username:
Password:

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

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

    No recent polls found