จัดเก็บ Double Quotes ตรงตัวใน MySQL: Escape ด้วย Backslash
ใน String Literal ของ MySQL (อยู่ใน Single Quotes) ให้ Escape Double Quotes ด้วย \\\"
ไวยากรณ์
INSERT INTO your_table VALUES('\\"your_value\\"');
สร้างตารางและข้อมูล
mysql> CREATE TABLE DemoTable (Name VARCHAR(20));
Query OK, 0 rows affected (0.63 sec)
mysql> INSERT INTO DemoTable VALUES('\\"John\\"'), ('\\"Chris\\"'), ('\\"Adam Smith\\"'), ('\\"Carol\\"');
Query OK, 4 rows affected
ผลลัพธ์: Double Quotes เป็นส่วนหนึ่งของข้อมูล
+--------------+ | Name | +--------------+ | "John" | | "Chris" | | "Adam Smith" | | "Carol" | +--------------+
Escape Sequences ใน MySQL String Literals
| Sequence | ความหมาย |
|---|---|
\\0 | NUL (ASCII 0) |
\\' | Single Quote |
\\" | Double Quote |
\\b | Backspace |
\\n | Newline (Line Feed) |
\\r | Carriage Return |
\\t | Tab |
\\Z | Ctrl+Z (Windows EOF) |
\\\\ | Backslash ตรงตัว |
\\% | % ตรงตัว (ใน LIKE) |
\\_ | _ ตรงตัว (ใน LIKE) |