addslashes(): escapes quotes, double quotes, backslashes, and NULLs with backslashes
<?php $escapedstring = addslashes("He said, 'I'm a dog.'"); $query = "INSERT INTO test (quote) values ('$escapedstring')"; echo($query); ?>