Simple Invoices logo
    • CommentAuthorrzelnik
    • CommentTimeJan 5th 2009
     permalink
    Hi all,
    Simple Invoice uses UTF-8 as a default encoding. That's great. But if you save any accented character (á, é, í, ó, etc.), you can see in the database admin (phpMyAdmin for example) that these characters are stored in wrong way - for example é is stored as á, á is stored as á etc. That's wrong. The reason is that most of the MySQL installations don't use UTF-8 as a default encoding. It's a latent bug, because in the output the characters are displayed well (they are encoded back to UTF-8 entities). The problem is that MySQL does not recognize that the text is UTF-8 encoded, so it stores these characters as HTML entities (á) or as two separacte characters instead of one two-byte UTF-8 character. This could cause errors in indexing, searching, etc.

    Solution:
    MySQL needs to know the character set of the connection.
    More info: http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html

    So in this case, I put this in sql_queries.php:

    $conn = mysql_connect( $db_host, $db_user, $db_password,true );
    $db = mysql_select_db( $db_name, $conn );
    $mysql = mysql_get_server_info(); //mysql_version
    mysql_query("SET NAMES utf8"); <--------------

    Warning: if you apply this fix in your existing installation, your existing data (accented characters) will be displayed damaged.
    They should be fixed manually or by some fixing script.

    Regards,
    Robert
    • CommentAuthorjustin
    • CommentTimeJan 5th 2009
     permalink
    Hey Robert,

    thanks for the post

    so even with DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci for each table in the .sql files for db creation its not enough?

    Cheers

    JustinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
    • CommentAuthorjustin
    • CommentTimeJan 5th 2009
     permalink
    just tested it - your right mysql doesnt store those characters correctly

    question: if you do a PDF for an invoice with those characters does it come out OK?

    below is the PDO code - i'll include this in the next release if testing is OK

    $connlink = new PDO(
    $pdoAdapter.':host='.$config->database->params->host.'; dbname='.$config->database->params->dbname, $config->database->params->username, $config->database->params->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
    );


    cheers

    justinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
    • CommentAuthorrzelnik
    • CommentTimeJan 6th 2009 edited
     permalink
    > so even with DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci for each table in the .sql files for db creation its not enough?

    no, that just says how the MySQL stores the data and how it orders them during db requests.

    SET NAMES 'charset_name'
    SET CHARACTER SET charset_name

    this specifies in which encoding the PHP communicates with the database.
    I don't know exactly the difference between NAMES and CHARACTER SET, IMHO it would be better to set both of them.

    regarding PDF: checked, works well, also XLS and DOC export.
    • CommentAuthorjustin
    • CommentTimeJan 6th 2009 edited
     permalink
    Thanks Robert

    I've set those 2 properties in our demo site http://www.simpleinvoices.org/demo

    if you can login and let me know if all is OK it would be great - also try doing some PDFs - we've had lots of problems in the past with non-latin and PDF

    Cheers

    JustinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
    • CommentAuthorrzelnik
    • CommentTimeJan 7th 2009 edited
     permalink
    Hello Justin,
    I have created a testing invoice and a testing product with some Slovak accented characters. They sill appear damanged.


    http://www.simpleinvoices.org/demo/index.php?module=products&view=details&id=189&action=view

    Note that the processing of non-latin characters includes many levels. The communication between db & app is just one of them. Other level is processing in WYSIWYG editor. For example in my local installation everything works well, except texts stored via WYSIWYG. I assume you use TinyMCE. I have some notes regarding TinyMCE & UTF compatibility. It's not so easy to force TinyMCE to process non-latin chars, but it is possible. Anyway I suggest to resolve the db level first.
    • CommentAuthordon_camillo
    • CommentTimeJan 14th 2009 edited
     permalink
    I also tested new PDF system. It is really great. In Turkish we have 7 special characters and as i tested now 4 of them are working but still 3 character are not shown properly.
    See the Invoice 586 for problem.

    Working characters are: çöiü
    not working characters are: ???
    edited: (how can i write them it is also not working in the post)
    • CommentAuthorjustin
    • CommentTimeJan 19th 2009
     permalink
    hey don

    re new pdf
    - did you test the same characters in the old pdf system?

    re how to post them
    - use the html codes for the characters to print them - and select bbcode as the post type

    let us know how you go

    cheers

    justinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
  1.  permalink
    Sorry it is my mistake. I now realized that my template which i am already using for months has do not have any problem about Turkish characters. (I am using Beta 1)

    But now i am begin to afraid. will it be a problem in the next version?