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.