SQLite throws a syntax error when executing an INSERT statement within a string value that contains single quotes. Escape single quotes with backslash (') or double backslash (') does not solve this problem.
To escape single quote characters in SQLite queries, double the single quotes in the string value:
<code class="language-sql">INSERT INTO table_name (field1, field2) VALUES (123, 'Hello there''s');</code>
This is because SQLite expects single quotes as delimiters for string literals, and this is clearly stated in its documentation:
<code>字符串常量是用单引号 (') 括起来的字符串。字符串中的单引号可以通过连续使用两个单引号来编码——就像在 Pascal 中一样。不支持使用反斜杠字符的 C 样式转义,因为它们不是标准 SQL。</code>
The above is the detailed content of How Do I Escape Single Quotes in SQLite INSERT Statements?. For more information, please follow other related articles on the PHP Chinese website!