doran has asked for the wisdom of the Perl Monks concerning the following question:
I have a test file I use to test escaping of 'special' characters:
Let's say I stick that into a variable $var and want to stuff it into a MySQL database table. To escape out these special characters, I run the variable through the DBI's quote() method:\ = backslash \\ = two backslashes \\\ = three backslashes ' = a single quote '' = two single quotes \' = a backslash and a single quote " = a double quote \" = a backslash and a double quote '"' = a double quote within 2 single quotes Here's a test of formatting and odd characters. This is the second line. Blank line above and some characters below: < = less than > = greater than & = ampersand & = an ampersand, a-m-p and a semicolon ! = exclamation
The problem, if it is one, is that when I look into the database, the single quotes are are properly escaped (ie. \') but the backslashes are not escaped (ie. a single backslash is represented by a single \ in the database).$var = $dbh->quote( $var ); # I could also use placeholders
Reading the DBI (and MySQL) docs, this doesn't seems to be the correct behaviour, since backslashes are supposed to be escaped with another backslash (ie. \\). So far I haven't gotten any errors and everything seems to be producing the expected results. But I'm wondering why this is. Is this correct behaviour? Shouldn't $dbh->quote() put an extra backslash in front of each backslash, or am I mistaken?
Also, please let me know if this is actually a MySQL question. I'm asking here because I'm using DBI's quote() function and I suspect that may be the culprit, for better or worse.
tia
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Backslashes with DBI quote( ) and MySQL
by gmax (Abbot) on Mar 06, 2002 at 08:04 UTC | |
by doran (Deacon) on Mar 06, 2002 at 18:13 UTC | |
Re: Backslashes with DBI quote( ) and MySQL
by lachoy (Parson) on Mar 06, 2002 at 02:52 UTC | |
Re: Backslashes with DBI quote( ) and MySQL
by webadept (Pilgrim) on Mar 06, 2002 at 07:25 UTC | |
Re: Backslashes with DBI quote( ) and MySQL
by Juerd (Abbot) on Mar 06, 2002 at 17:38 UTC | |
by gmax (Abbot) on Mar 07, 2002 at 07:53 UTC |
Back to
Seekers of Perl Wisdom