This is provided by MySQL, as an example:
http://dev.mysql.com/doc/refman/5.0/en/mysql-real-escape-str...
I'm sure what you meant was a server-side escaping function which is obviously pointless, but I did want to point out that MySQL's client driver does ship with one that you can use so you don't have to write your own.