MySQL Forums
Forum List  »  PHP

Re: Encoding problem...
Posted by: Ted Ashton
Date: August 06, 2010 02:17PM

Hi,

Many thanks for your reply Rick. I have a little more information.

I have written a little php script to query the database - as opposed to going through Website Baker. I'll show the script at the end of this post. I have run the script on the local/remote machines in both the terminal and as a web page.


LOCAL SERVER

In local terminal (utf-8) it displays:
261, Добро пожаловать в Диксон, На главную
399, Kelepçeler, Kelepçeler

In local terminal (Latin1) it displays:
261, Добро пожаловать в Диксон, На главную
399, Kelepçeler, Kelepçeler

And on local web server:
261, Добро пожаловать в Диксон, На главную
399, Kelepçeler, Kelepçeler


REMOTE SERVER

In remote terminal (utf-8 set via export LANG="en_GB.UTF-8") it displays:
261, ????? ?????????? ? ??????, ?? ???????
<br />399, Kelep?eler, Kelep?eler

In remote terminal (latin1 set via export LANG="en_GB.latin1") it displays:
261, ????? ?????????? ? ??????, ?? ???????
399, Kelep?eler, Kelep?eler

And in remote web server:
261, ????? ?????????? ? ??????, ?? ???????
399, Kelep�eler, Kelep�eler


AMENDMENT

Adding the line - as suggested earlier in this series of posts:

mysql_query("SET NAMES 'utf8'");

to my test script resolves my character encoding issues. I've also had a good dig around on the Website Baker site and found this page:

http://www.websitebaker2.org/topics/trouble-with-characters.php

Near the bottom of this page under the heading ERROR 2, it states "character-set of WB database must be set to the default-character-set defined by your service provider."

So it seems there are two solutions to this:

1) Hack Website Baker and add mysql_query("SET NAMES 'utf8'"); just after making any connection to the database.

2) As the site is on a shared hosting plan the hosting company are understandably reluctant to convert everything to utf8, and hence the alternative is to get a VPS or such like and make sure the mysql server and everything on it is utf8.

Option 2) is probably a bit overkill and expensive unless it really is necessary, which leaves option 1). My preliminary effort has successfully added this line to the relevant file (/framework/class.database.php). I'm loathed to do this fearing future problems, but for now this might be the fix I am looking for.

As this fix is rather specific to Website Baker, I am going to post for further advice on the Website Baker forum, but will post my final solution back here.

Unless anyone has any further comments or suggestions, I thank you sincerely for pointing towards the problem and solution.

Cheers,

Chris



SCRIPT

<?php
mysql_connect("localhost", "######", "######") or die(mysql_error());


mysql_select_db("######") or die(mysql_error());

$query = sprintf("SELECT page_id, page_title, menu_title FROM pages WHERE page_id = 399 OR page_id = 261;");

$result = mysql_query($query);

if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
';

while ($row = mysql_fetch_assoc($result)) {
echo "\n<br />" .$row['page_id'] . ", " . $row['page_title'] . ", " . $row['menu_title'];
}

echo '
</body>
</html>
';

mysql_free_result($result);
?>

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
Re: Encoding problem...
August 06, 2010 02:17PM
August 06, 2010 11:01PM
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.