Your question is a wonderful collection of confusion. You are all confused. Let's try to figure it out.
Using PHP, what is the best way to store special characters (like the following) in the MSQUL database to avoid injections.
These are incomparable matters. Keeping special characters is one thing, and avoiding injections is another. completely different.
$book_text=htmlentities($book_text, "ENT_QUOTES");
This is the funniest part. although it is designed to protect your requests, it actually does nothing. Since instead of the constant ENT_QUOTES, whose value is 3, you use the string ENT_QUOTES, whose numeric value is 0, so you do not set the flag.
But even if you set this flag correctly, it will not automatically protect you. Since the injection code may not contain special characters.
To avoid injections, you should follow entire sets of rules , not just one simple function, make_my_data_safe (). There is no magic wand.
See this my answer for more details.
Regarding special characters, it's simple. The only problem is that there are no special special characters. There are different special characters for different environments.
- 'matter for database and HTML
- <> are relevant only for HTML
- é à ù make sense only for HTML, it depends on the encoding.
You have different formatting rules for each case. Different, not one for everyone.
To use à à ars characters with HTML, you must set the correct HTTP header. To use é à ù with a database, you must set the table encoding to utf8 and the connection encoding to utf 8.