Correctly Escaping Single Quotes in SQLite INSERT Statements
When working with SQLite databases, you might encounter issues inserting data containing single quotes. Incorrectly escaping these quotes leads to errors. For example, the statement:
<code class="language-sql">INSERT INTO table_name (field1, field2) VALUES (123, 'Hello there\'s');</code>
will fail. SQLite, following standard SQL practices, doesn't use backslashes () for escaping within string literals.
The solution is to double the single quote within the string:
<code class="language-sql">INSERT INTO table_name (field1, field2) VALUES (123, 'Hello there''s');</code>
This correctly escapes the single quote, allowing the INSERT
statement to execute successfully. This doubling method ensures proper interpretation of the string literal within the SQLite query.
The above is the detailed content of How Do I Properly Escape Single Quotes in SQLite INSERT Statements?. For more information, please follow other related articles on the PHP Chinese website!