I've actually found that PHP's method of escaping single quotes with a slash is incompatible with Oracle, the database I'm using. In fact all the database's I've used require that single quotes are escaped with double single quotes, not a prefixed backslash.
So, the statement INSERT 'It's a nice day' should be INSERT 'It''s a nice day'. Most databases will choke on the statement 'It\'s a nice day'.
In fact, I've gone so far as to disable PHP's MAGIC_QUOTES_GPC global setting, which basically runs all GET, POST, and COOKIE vars through the AddSlashes() function automatically, later requiring proper output of these string to be ran through the StripSlashes() function. What a pain. It only gets in the way for me and makes handling database input and output a major chore, in addition to handling user input and output. I never know when PHP has modified the variable's content behind my back, and I have to basically guess when I need to use StripSlashes(). It's too confusing.
In a nutshell, for queries, you can use the Str_Replace() function to replace single quotes with double quotes:
Str_Replace("'", "''", $string)
I like to have a function that does this, so I can re-use the code and even modify it for all queries in one place. Hint: a function called "QueryEncode()" might be handy to encode all client-based variables in SQL statements.
As for form output, you sort of run into the same problem if the value has a double quote in it, so a similar function that converts double quotes into HTML entities (such as the HTMLSpecialChars() function) is a good idea too. Again, creating your own function to do this, such as "FormEncode()" might be handy.
Maybe I'm missing the advantage of the MAGIC_QUOTES settings in PHP, and maybe MySQL and/or Postgress prefer dealing with the slash-escaped single quotes. And maybe there's a setting in Oracle to handle PHP-espaced strings better. However, for PHP to assume that the database wants slash-escaped characters is quite wrong, and for it to manipute client variables is ever worse, espeically to users who don't know what's going on behind the scenes.