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
In reply to Backslashes with DBI quote( ) and MySQL by doran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |