in reply to CGI/DBI and placeholders, revisited.

Well, ive noticed on win32 perl/apache/mysql, that mysql or dbi or somesuch dies when you try to call a method on sql containing a semicolon. I.e. prepare("select * from my_table"); works but prepare("select * from my_table;"); tends to die on me.
  • Comment on Re: CGI/DBI and placeholders, revisited.

Replies are listed 'Best First'.
Re: Re: CGI/DBI and placeholders, revisited.
by mpeppler (Vicar) on May 04, 2002 at 20:54 UTC
    You've got to remember that the ';' is not part of the SQL syntax. It's interpreted by the command line tool that you use to access MySQL (or Oracle, or Sybase...) as a statement separator.

    Michael

      OK, well, if this is the case, and neither do() nor prepare() will work if given a string with a semicolon (as if someone had tried to insert a second statement in the form), then why all the hubbub about using placeholders and worrying about someone trying to execute extra commands? Or am I missing something? (I probably am.) Can somebody point me to an explanation somewhere? Thanks.
        OK, well, if this is the case, and neither do() nor prepare() will work if given a string with a semicolon (as if someone had tried to insert a second statement in the form), then why all the hubbub about using placeholders and worrying about someone trying to execute extra commands?

        The behavior is database dependent. Though there appears to not be a problem with MySQL, the advice to not construct queries from un-detainted pieces is still sound. Scripts written with one database in mind tend to migrate to other platforms, or are used as templates for new scripts. It's better to "get things right" even if there's no direct risk on the current platform mix.

    A reply falls below the community's threshold of quality. You may see it by logging in.