Languages
[Edit]
EN

MySQL - escape apostrophe (')

7 points
Created by:
Geo-Baby
300

In this short article, we would like to show how to escape apostrophe (') in string values using MySQL.

Quick solutions:

  1. use '', e.g.
    SELECT 'Some ''text'' here ...'
  2. use \', e.g.
    SELECT 'Some \'text\' here ...'

 

Practical examples

1 SELECT query

SELECT 'Some ''text'' here ...';

or:

SELECT 'Some \'text\' here ...';

INSERT query

INSERT INTO `table_name`
    (`column_name`)
VALUES
    ('Some ''text'' 1 here ...'),
    ('Some ''text'' 2 here ...'),
    ('Some ''text'' 3 here ...');

or:

INSERT INTO `table_name`
    (`column_name`)
VALUES
    ('Some \'text\' 1 here ...'),
    ('Some \'text\' 2 here ...'),
    ('Some \'text\' 3 here ...');

Alternative titles

  1. MySQL - escape apostrophe (') in string value
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join