使用 PHP,在 MSQUL 数据库中存储特殊字符(如下所示)以避免注入的最佳方法是什么。
« " ' é à ù
这就是我现在的做法:
$book_text=$_POST['book_text'];
$book_text=htmlentities($book_text, "ENT_QUOTES");
$query=//DB query to insert the text
然后:
$query=//DB query to select the text
$fetch=//The fetch of $book_text
$book_text=html_entity_decode($book_text);
这样,我所有的文本都被格式化为 HTML 实体。但是我认为这会占用大量的数据库空间。那么,有没有更好的方法呢?