Home >Database >Mysql Tutorial >How Do I Properly Escape Single Quotes in SQLite INSERT Statements?

How Do I Properly Escape Single Quotes in SQLite INSERT Statements?

DDD
DDDOriginal
2025-01-15 12:06:44280browse

How Do I Properly Escape Single Quotes in SQLite INSERT Statements?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn