[PHP] Re: Unicode problems

2008-09-26 Thread Nathan Rixham

Thiago H. Pojda wrote:

This is slightly OT but I honestly don't know what else I can do.

I was asked to migrate a website from diff hosts. Okay, pretty easy, right?
Well, as usual, it wasn't.

Site pages content type was ISO-8559-1 and it was developed for a MySQL5
database that used latin1 as charset and InnoDB as storage system. Pretty
normal and ran smoothly.

The client database is a old 4.0 MySQL that (I'm not sure if they're just
disabled but it) doesn't have InnoDB and latin1. So I'm stuck with MyISAM
and UTF8. No, they can't change it - their hosting want them to migrate to
MSSQL and they can't switch hosts for whatever reason.

After I uploaded the files and ran it, my HTML files displayed correctly but
all accented chars that came from DB were displayed with weird chars, as I
imagined it would.

I then set my html content type to UTF-8 and I also had problems, but in
backwards this time - DB values were OK and website content was bad.

I couldn't find any good function/script to convert all my files to UTF-8
and then I built my own. It uses iconv and works like a charm. But
unfortunately I still can't get all pages to work. I have no idea why or
how, but *some* queries return the text in ISO-8859-1. I even dropped the
table and recreated them explictly saying it's a UTF8 table but some rows
are in ISO and others in UTF-8 (that or some mysql_fetch_* functions
converts them).

It's been 2 days and I still can't see a solution. I even thougth of adding
utf_decode on all of mysql_fetch* results, but I didn't build this website
so I don't feel like adding that in *every* call (it doesn't have a wrapper
for mysql_* functions).

So, I'm here to humbly ask for your help. What can be wrong?

PHP Version is 4.4.8

Thanks,


you could simply dump the database via the command line, utf8_encode the 
generated sql file, then drop it back in (?)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Unicode problems

2008-09-26 Thread Thiago H. Pojda
Hello,

On Fri, Sep 26, 2008 at 9:07 AM, Daniel Jaeger  wrote:

 I had similar problems, I cant get the whole situation out of what you
 wrote but here are two hints.

 If you got SSH Access you can try to import the DB by following command


I don't have SSH access :/


 Otherwise if you can't access the server on this way you can set the whole
 DB connection on the PHP application to the wanted charset by using
 following function mysql_set_charset - but as this one just works on PHP
 5.2.3 you can do the same (not recommendet way) over the Set names
 MysqlQuery - this Query just needs to be run after the connection has been
 established (mysql_connect()).


Tried without success.

 Just have a look at the doc of the mysql_set_charset function there you see
 on the third comment a implementation of this function for all who have an
 earlier PHP Version than 5.2.3 (
 http://de3.php.net/manual/de/function.mysql-set-charset.php)

 Hope I could help.


Actually all the responses did help. While I was researching I figured some
weird stuff. I tried MySQL 4.0 examples for CAST() and CONVERT() and all I
got were syntax errors. This DB is broke.



 Cheers
 Daniel


I did the following:

1) Extract the DB script from the working one;
2) Manually added CHARSET=utf8 for each create table;
3) Converted this script to UTF8 and opened with a ANSI reader and all the
accented chars got funny. Great! That's what I wanted.
4) Applied the script into the database and more frustration. *Some* lines
were in utf8 and some in latin1.

I can only imagine the hosting is forcing this kind of behaviour so the
client has to switch DBMS. (I don't see how, but well).

I'm still trying and researching. If anyone else have any idea, please
reply.

Thanks everyone!

-- 
Thiago Henrique Pojda


[PHP] Re: Unicode problems

2008-09-26 Thread Ross McKay
On Fri, 26 Sep 2008 10:39:33 +0100, Nathan Rixham wrote:

 [...]
 I couldn't find any good function/script to convert all my files to UTF-8
 and then I built my own. It uses iconv and works like a charm. But
 unfortunately I still can't get all pages to work. I have no idea why or
 how, but *some* queries return the text in ISO-8859-1. I even dropped the
 table and recreated them explictly saying it's a UTF8 table but some rows
 are in ISO and others in UTF-8 (that or some mysql_fetch_* functions
 converts them).

Can you confirm: are you telling your PHP connection into MySQL to use
Unicode? e.g. tell MySQL directly by executing the following statement:

set names 'utf8'

Also, is some of your data going through htmlentities() and coming out
wrong? If so, look at specifying the character set:

htmlentities($someText, ENT_COMPAT, 'utf-8');
-- 
Ross McKay, Toronto, NSW Australia
Let the laddie play wi the knife - he'll learn
- The Wee Book of Calvin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Unicode problems - solve

2008-09-26 Thread Thiago H. Pojda
Sorry to bother you all, I just did the whole process again using only
phpmyadmin and notepad++ (yes, I'm under windows) I could import the
database successfully. The whole thing was converted to UTF8.

@Richard:

I'm using both, META and header. I didn't know IE6 had issues with header(),
learning somehing new every day :)

About UTF8, if you have text in ISO (latin1) and tell the browser it's a
UTF8 it doesn't work 100%. Not the accented chars.


Thanks for all the help,
-- 
Thiago Henrique Pojda