EN
MySQL - escape apostrophe (')
7
points
In this short article, we would like to show how to escape apostrophe (') in string values using MySQL.
Quick solutions:
- use
'', e.g.SELECT 'Some ''text'' here ...' - use
\', e.g.SELECT 'Some \'text\' here ...'
Practical examples
1 SELECT query
SELECT 'Some ''text'' here ...';
or:
SELECT 'Some \'text\' here ...';
2 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 ...');