Search code examples
mysqldatabasestringescapingquotes

How to escape single quotes in MySQL?


How do I insert a value in MySQL that consist of single or double quotes. i.e

This is Ashok's Pen.

The single quote will create problems. There might be other escape characters.

How do you insert the data properly?


Solution

  • Put quite simply:

    SELECT 'This is Ashok''s Pen.';

    So inside the string, replace each single quote with two of them.

    Or:

    SELECT 'This is Ashok\'s Pen.'

    Escape it =)