skyline — 2012-09-15T09:32:20-04:00 — #1
I'm running a php script to populate a mysql table from a txt file.
My db table is set to utf-8.
I run the php vis ssh and echo the queries and sure enough it's telling me each insert has the non-ascii chars.
But when I check the db table, it seems to be bailing that field at the non-ascii chacter:
INSERT INTO cities VALUES('','ad','Aixàs')
Should be: Aixàs
i've been trying all sorts and nothing works. I've tried setting some stuff just after connection in the php:
mysql_query("SET NAMES UTF8", $con);
mysql_query("SET character_set_results=utf8", $con);
mysql_query("SET character_set_client=utf8", $con);
mysql_query("SET character_set_connection=utf8", $con);
Any ideas most appreciated?
skyline — 2012-09-15T10:19:25-04:00 — #2
I should add: If I copy the query to my editor (sqlyog) and execute it enters the correct non-ascii fine!
On investigation the php file itself is us-ascii and I can't seem to convert to the UTF-8 without BOM that I need to for my server to display characters correctly on websites!
I use notepad++ and it just keeps setting back to ascii. I've tried creating a new file, encoding in UTF-8 without BOM and copying the code across but still fails to convert.
At a loss. This server has always had these weird character issues!
lemon_juice — 2012-09-16T11:46:23-04:00 — #3
I use notepad++ very rarely but I remember having some problems in it with converting files to utf-8 or reading them as utf-8. But I just didn't care enough to dig that problem deeper so I can't really say how to configure notepad++ properly (if it's possible at all).
A good editor that handles utf-8 well is a must and it's the first step to cure such problems and I doubt it's a server issue. Try another editor and see what happens. Now I use Netbeans set to utf-8, I have also used jEdit for quite a long time and occasionally I use EditPadLite for simple edits - all of these can handle utf-8 without any problem.
kduv — 2012-09-17T20:20:04-04:00 — #4
You can also check out PHP's utf8_encode() function to convert ASCII to UTF8 within PHP.
mittineague — 2014-09-18T22:43:25-04:00 — #5
This topic is now archived. It is frozen and cannot be changed in any way.