in reply to Mysql queries with ' and "
Just modify your $insert_query first, to escape all occurrences of apostrophe "'":
$insert_query =~ s/'/\\'/g;
This changes each "'" into "\'" (you have to escape the backslash "\" in the regular expression, which why there are two).
Update: I agree with runrig that $dbh->quote is preferrable (as is using placeholders). On second look my way wouldn't quite work anyway, since you've got apostrophes within the string, though you could still get away with the regex if it didn't contain apostrophes to begin with; eg.:
insert_query = qq{INSERT INTO arabic_corpus (crps_word, crps_count +) VALUES ("$word", "$count")}; $insert_query =~ s/'/\\'/g;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Mysql queries with ' and "
by runrig (Abbot) on Mar 12, 2014 at 20:23 UTC | |
by fattahsafa (Sexton) on Mar 12, 2014 at 20:36 UTC |