samedi 11 avril 2015

Escape string with single quotes in PHP for SQLite

I would like to store the following string in the field of an SQLite table:



$string = "Einstein's equation";


Is there a function to do so in a safe way? Obviously



SQLite3::escapeString($string);


does not work. Instead it will return Einstein"s equation.


I read that in SQL one is supposed to use double single quotes for single quotes, i.e., Einstein''s equation. However, if I try to make it safe SQLite3::escapeString("Einstein''s equation") returns Einstein""s equation. Is that a bug of escapeString?


What would be the correct way to escape a string with single quotes properly?


Aucun commentaire:

Enregistrer un commentaire