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 |