MySQL Forums
Forum List  »  PHP

Re: Encoding problem...
Posted by: Ted Ashton
Date: August 08, 2010 04:01PM

Hi Rick,

Thanks again for your response. Unfortunately I do not have access to /etc/my.cnf on either the staging of final server. I presume the command you suggested (init_connect = 'SET NAMES utf8' ) needs to go under the [mysqld] section. In any case, when I put it under the [client] section on my local server starting the mysql client gave an error - something like invalid syntax, I presume because the server controls the connection encoding? I also presume placing this line in ~/.my.cnf wouldn't work?

On your suggestion I amended my test php script to use the following query:


$query = sprintf("
SELECT page_id,
page_title,
HEX(page_title) as hex,
LENGTH(page_title) as len,
CHAR_LENGTH(page_title) as charlen
FROM pages WHERE page_id = 399 OR page_id = 261;");

while ($row = mysql_fetch_assoc($result)) {
echo "\n<br />";
echo "\n<br />page_id: " . $row['page_id'] . ", " .
"\n<br />page_title: " . $row['page_title'] . ", " .
"\n<br />hex: " . $row['hex'] . ", " .
"\n<br />length: " . $row['len'] . ", " .
"\n<br />char length: " . $row['charlen'];
}


Note: the above code does NOT contain the line mysql_query("SET NAMES 'utf8'");

On the local test server (configured as in previous posts) where all the characters are displayed as they should, the script when viewed in a browser displays:

page_id: 261,
page_title: Добро пожаловать в Диксон,
hex: D094D0BED0B1D180D0BE20D0BFD0BED0B6D0B0D0BBD0BED0B2D0B0D182D18C20D0B220D094D0B8D0BAD181D0BED0BD,
length: 47,
char length: 25

page_id: 399,
page_title: Kelepçeler,
hex: 4B656C6570C3A7656C6572,
length: 11,
char length: 10


When I view the same script on the staging server I get:

page_id: 261,
page_title: ????? ?????????? ? ??????,
hex: D094D0BED0B1D180D0BE20D0BFD0BED0B6D0B0D0BBD0BED0B2D0B0D182D18C20D0B220D094D0B8D0BAD181D0BED0BD,
length: 47,
char length: 25

page_id: 399,
page_title: Kelep�eler,
hex: 4B656C6570C3A7656C6572,
length: 11,
char length: 10


Adding the line mysql_query("SET NAMES 'utf8'"); immediately following the connection on the staging server script gives:

page_id: 261,
page_title: Добро пожаловать в Диксон,
hex: D094D0BED0B1D180D0BE20D0BFD0BED0B6D0B0D0BBD0BED0B2D0B0D182D18C20D0B220D094D0B8D0BAD181D0BED0BD,
length: 47,
char length: 25

page_id: 399,
page_title: Kelepçeler,
hex: 4B656C6570C3A7656C6572,
length: 11,
char length: 10

It seems the hex, length and char length is the same in all instances.

Kind regards,

Chris

Options: ReplyQuote


Subject
Written By
Posted
July 30, 2010 07:04AM
July 30, 2010 07:43AM
August 01, 2010 02:33PM
August 04, 2010 02:53PM
August 04, 2010 02:59PM
August 02, 2010 11:52AM
August 02, 2010 06:10PM
August 02, 2010 08:42PM
August 05, 2010 12:30AM
August 05, 2010 12:33AM
August 05, 2010 12:35AM
August 05, 2010 12:37AM
August 05, 2010 08:43AM
August 06, 2010 02:17PM
August 06, 2010 11:01PM
Re: Encoding problem...
August 08, 2010 04:01PM
August 08, 2010 06:16PM
August 05, 2010 12:40AM
September 01, 2010 12:53PM
September 01, 2010 10:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.