LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Tags used in this thread
Popular LQ Tags , , , , ,

Reply
 
Thread Tools
Old 12-19-2008, 12:20 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,174
Blog Entries: 1
Thanked: 0
Question Problems with mysql, php and utf8


[Log in to get rid of this advertisement]
Hi!

I want to show some data that I have on a DB.

When I connect with the terminal client, when I do a select, I get exactly the data I expected AND when I check with one sniffer, I see that the data that is being transfered on the wire is exactly that data in UTF8. Cool.

However, when I try to do the same from PHP, I just don't get the render some of the characters correctly. I have tried setting the client encoding with these (with different combinations and each one separate):
Code:
mysql_set_charset('utf8', $LINK);
mysql_query("SET NAMES 'utf8'", $LINK);
mysql_query("set character set 'utf8'", $LINK);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $LINK);
When I check with the sniffer, no matter what I do, I never get the same bytes on the wire (onr on the script result, by the way). For instance "ó" would be sent as 0xc3 0xb3 to the terminal (as expected), but when I do that on php, this is sent to the client instead: 0xc3 0x83 0xc2 0xb3

Any idea what's going on?

It's PHP5 on Ubuntu Intrepid.
eantoranz is offline  
Tag This Post , , , , ,
Reply With Quote
Old 12-20-2008, 02:05 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 11
Posts: 1,860
Thanked: 26
I would guess that PHP is not handling the UTF8 conversion correctly. Check the documentation on mbstrings and change the ini file as directed by that chapter. You may get some success then.
graemef is offline     Reply With Quote
Old 12-20-2008, 10:25 AM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,174
Blog Entries: 1
Thanked: 0

Original Poster
I'll check... but then how come the data is coming _not_ in utf8 on the wire? That's not related to PHP, or is it?

Last edited by eantoranz; 12-20-2008 at 10:49 AM..
eantoranz is offline     Reply With Quote
Old 08-04-2009, 06:45 PM   #4
lbharti
Member
 
Registered: Aug 2004
Posts: 41
Thanked: 0
Question I have the same problem

In fact, I also tested PHP5 with UTF-8 static data, and it displays alright after setting the header with charset utf-8, or setting the default charset to utf-8.

MySQL client displays the data just the way it is supposed to. I have enable three other options in my.cnf, but to no help.

init-connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci

Could you get it working? Please share the info if you did.

Thanks
lbharti is offline     Reply With Quote
Old 08-05-2009, 02:11 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 11
Posts: 1,860
Thanked: 26
What are the mbstring settings in php.ini
graemef is offline     Reply With Quote
Old 08-05-2009, 03:13 AM   #6
lbharti
Member
 
Registered: Aug 2004
Posts: 41
Thanked: 0
Here are the values. I am using Ubuntu Hardy Heron.
mbstring
Multibyte Support enabled
Multibyte string engine libmbfl
HTTP input encoding translation enabled
Multibyte (japanese) regex support enabled
Multibyte regex (oniguruma) version 4.4.4
Multibyte regex (oniguruma) backtrack check On


Directive Local Value Master Value
mbstring.detect_order no value no value
mbstring.encoding_translation On On
mbstring.func_overload 0 0
mbstring.http_input pass pass
mbstring.http_output UTF-8 UTF-8
mbstring.internal_encoding UTF-8 UTF-8
mbstring.language neutral neutral
mbstring.strict_detection Off Off
mbstring.substitute_character no value no value
lbharti is offline     Reply With Quote
Old 08-05-2009, 04:23 AM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 11
Posts: 1,860
Thanked: 26
The key settings are (I believe)

mbstring.http_input UTF-8
mbstring.internal_encoding UTF-8
mbstring.http_output UTF-8
mbstring.detect_order auto

taken from a web server that I have running.

You may want to modify your settings to be in line with these and then check.

If that doesn't help then how are you getting the data off the database and then displaying it on the screen?
graemef is offline     Reply With Quote
Old 08-05-2009, 11:28 AM   #8
lbharti
Member
 
Registered: Aug 2004
Posts: 41
Thanked: 0
Thanks for the prompt reply. I use mysql_connect to connect to the local database, the usual way. The data displays correct in the mysql terminal client, just PHP is either not receiving the correct data, or is messing it up. How do I trace this behavior?
lbharti is offline     Reply With Quote
Old 08-05-2009, 11:44 AM   #9
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,174
Blog Entries: 1
Thanked: 0

Original Poster
Chck with one sniffer what's being transfered through the wire. Maybe you will see the same error I saw on the wire transfer.
eantoranz is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql utf8 traditional simplified chinese load data infile secretlydead Linux - Server 3 02-11-2008 11:35 AM
MySQL 4.1. support UTF8 treotan General 0 09-09-2005 02:13 AM
mysql/php/phpmyadmin/utf8 kenji1903 Linux - Software 6 09-03-2005 07:36 AM
PHP Problems with Mysql MattJohnson Linux - Newbie 3 11-23-2004 12:12 PM
PHP Problems with Mysql MattJohnson Linux - Networking 1 11-23-2004 10:19 AM


All times are GMT -5. The time now is 02:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration