in reply to Escaping a string

quotemeta. The command line will be tough to test this on, since the shell will interfere.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Escaping a string
by Anonymous Monk on Mar 13, 2003 at 20:49 UTC
    I'm doing from within perl - I define and declare the string in perl, and send the result to mysql. Plus, how do I convert "D\'ith" to "D'ith". Thank you.

      If you are using DBI to access MySQL then something like this may be better.

      use DBI; my $dbh=DBI->connect('DSN info here'); my $string="D'ith"; my $val_to_put_in_mysql=$dbh->quote($string);

      Or if you are using placeholders in your query then DBI will do the quote on insert for you. Either way DBI will fetch it back as D'ith for you.

      From the DBI docs:
      use DBI; $quoted_string = $dbh->quote($string);
      If my understanding of black magic is correct that should take care of your quoting on the way into the DB. You should be able to select, etc. at will and have it come back out of the DB in its original (unescaped) form.
        THanks, out of interest, how would I escape using a regex.