0

Trying to get a simple insert saving data and the french characters are read back as box characters. How can I fix this?

$query = 'insert into category (category_en, category_fr) values
                            ("Seamanship", "Matelotage"),
                            ("General - Histoiry", "Généralités - Histoire")),
                            ("Sailing", "Voile")';

When I display the results, I am seeing:

G�n�ralit�s � Histoire

I already noted that if I manually change these characters to be é that I can save them correctly.

However this does not apply when saving directly from input fields in a form. All French characters in this case are being saved correctly.

I tried to apply SQLite3.escapestring to the query above but it still failed.

Just wondering is there a more straight forward way instead of manually changing each character?

SOLUTION

utf8_encode() does the trick.

$query = utf8_encode('insert into category (category_en, category_fr) values
                                ("Seamanship", "Matelotage"),
                                ("General - Histoiry", "Généralités - Histoire")),
                                ("Sailing", "Voile")';

Honestly when forms input fields save french characters correctly one would believe a hardcoded statement would be pretty logical. Hope this helps anyone looking for a quick solution.

mcv
  • 1,380
  • 3
  • 16
  • 41
  • @Fred -ii- my question inputs are saving inputs using french characters correctly, it`s this single hardcoded string which that is failing and the reference you have selected if for MySQL not SQLite. How does this help? – mcv Sep 20 '17 at 13:04
  • It helps because the error you get (seeing the corrupted characters) is caused by a wrong encoding at some point in your application. Read the link. Your question as it stands is way too broad, because of the multiple possibilities where you could have failed to properly encode characters / set encoding. Also please do not change characters to &eacute. This is not solving the problem, it's just pushing it to the next you that will have to deal with it. – Félix Adriyel Gagnon-Grenier Sep 20 '17 at 13:13
  • okay from digging thur all the information I figured it out, but I do not believe either of the resources quoted above said this could be resolved using PHP utf8_encode() Function. – mcv Sep 20 '17 at 13:42

0 Answers0