SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Queries not saving UFT-8 chars

    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:

    eg

    INSERT INTO cities VALUES('','ad','Aixs')

    Should be: Aixs
    Stored: Aix

    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?

  2. #2
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  3. #3
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Atlanta, GA
    Posts
    244
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You can also check out PHP's utf8_encode() function to convert ASCII to UTF8 within PHP.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •