One thing to note here - don't know if it applies to all DB2 installations, and I know I'm using an antiquated one, but my DB2 install wants a ' to be quoted rather than slashed.
That means this function is useless to pick up apostrophes ' in strings, as it adds a slash which DB2 ignores.
You'll need to use something like str_replace to swap your ' for ''.