How do I get the ' entered successfully in a MySQL database with Perl script ?
$data = "it's best that you quote your strings"
######################################## # HERE'S THE MAGIC BIT OF CODE YOU NEED! $data_to_insert = $dbh->quote($data); ########################################
$sth = $dbh->prepare("INSERT INTO mytable VALUES mystring=" . $data_to_insert); $rv = $sth->execute;
--
The $dbh->quote function correctly wraps the string in single quotes and escapes the single quote in the string with a backslash, and also correctly escapes any backslashes, etc.
So $data_to_insert will look like this:
'it\'s best that you quote your strings'
-- Del
-- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug