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

Reply
 
Search this Thread
Old 12-19-2008, 11:20 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Question Problems with mysql, php and utf8


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.
 
Old 12-20-2008, 01:05 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.
 
Old 12-20-2008, 09:25 AM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
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 09:49 AM.
 
Old 08-04-2009, 05:45 PM   #4
lbharti
Member
 
Registered: Aug 2004
Posts: 41

Rep: Reputation: 15
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
 
Old 08-05-2009, 01:11 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
What are the mbstring settings in php.ini
 
Old 08-05-2009, 02:13 AM   #6
lbharti
Member
 
Registered: Aug 2004
Posts: 41

Rep: Reputation: 15
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
 
Old 08-05-2009, 03:23 AM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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?
 
Old 08-05-2009, 10:28 AM   #8
lbharti
Member
 
Registered: Aug 2004
Posts: 41

Rep: Reputation: 15
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?
 
Old 08-05-2009, 10:44 AM   #9
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
Chck with one sniffer what's being transfered through the wire. Maybe you will see the same error I saw on the wire transfer.
 
  


Reply

Tags
mysql, mysql5, php, php5, ubuntu810, utf8


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:35 AM
MySQL 4.1. support UTF8 treotan General 0 09-09-2005 01:13 AM
mysql/php/phpmyadmin/utf8 kenji1903 Linux - Software 6 09-03-2005 06:36 AM
PHP Problems with Mysql MattJohnson Linux - Newbie 3 11-23-2004 11:12 AM
PHP Problems with Mysql MattJohnson Linux - Networking 1 11-23-2004 09:19 AM


All times are GMT -5. The time now is 02:06 PM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration