Connecting Tech Pros Worldwide Forums | Help | Site Map

MySQL 4.1 / PHP 5.0 : Unicode problems

roland.saad@gmail.com
Guest
 
Posts: n/a
#1: Oct 20 '06
Hi Everyone,

I have been trying to build a website that has multilingual support
using the LAMP setup. I have created tables that store language
information and correlate different strings ids with languages. The
strings are all VARCHAR with unicode (utf8) encoding.

I have tried all the ways that I could think of and I have checked
every website to no avail. What I am trying to do is simply open a
connection to the database (using mysqli) and query the tables for one
unicode string entry. Then I call fetch_object on the result and print
it to an HTML document. This fails with me. The characters I see are
not unicode but either ??????? or some weird character. Aparently the
encoding turns out to be ISO-8859-1.

I have done the following:
1. Create the entries in the MySQL tables as unicode in InnoDB tables.
Unicode text shows up properly in phpmyadmin.
2. Query correctly to the best of my knowledge using mysqli.
3. Add the proper header encoding to the http header and add this meta
tag to the html:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

Everything I have read says that this should work even though PHP is
notorious for unicode support. What I have been able to narrow down the
problem to is that the string that I get back from the database is
latin encoding. I know it is unicode from MySQL (phpmyadmin), so I
assume the problem lies in the mysqli_query function call or with the
fetch_object call.

Please help, I have been stuck on this for days now.

Thanks
Roland


petersprc@gmail.com
Guest
 
Posts: n/a
#2: Oct 21 '06

re: MySQL 4.1 / PHP 5.0 : Unicode problems


Maybe this will help:

mysqli_set_charset('utf8');

roland.saad@gmail.com wrote:
Quote:
Hi Everyone,
>
I have been trying to build a website that has multilingual support
using the LAMP setup. I have created tables that store language
information and correlate different strings ids with languages. The
strings are all VARCHAR with unicode (utf8) encoding.
>
I have tried all the ways that I could think of and I have checked
every website to no avail. What I am trying to do is simply open a
connection to the database (using mysqli) and query the tables for one
unicode string entry. Then I call fetch_object on the result and print
it to an HTML document. This fails with me. The characters I see are
not unicode but either ??????? or some weird character. Aparently the
encoding turns out to be ISO-8859-1.
>
I have done the following:
1. Create the entries in the MySQL tables as unicode in InnoDB tables.
Unicode text shows up properly in phpmyadmin.
2. Query correctly to the best of my knowledge using mysqli.
3. Add the proper header encoding to the http header and add this meta
tag to the html:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
>
Everything I have read says that this should work even though PHP is
notorious for unicode support. What I have been able to narrow down the
problem to is that the string that I get back from the database is
latin encoding. I know it is unicode from MySQL (phpmyadmin), so I
assume the problem lies in the mysqli_query function call or with the
fetch_object call.
>
Please help, I have been stuck on this for days now.
>
Thanks
Roland
roland.saad@gmail.com
Guest
 
Posts: n/a
#3: Oct 21 '06

re: MySQL 4.1 / PHP 5.0 : Unicode problems


Yes thanks!!! That did it! Wow, 4 days of debugging for this!

Thanks a lot.

However, i have a problem with my versions. I am running locally on
WAMP 1.6.3 and the function seems to be missing. However on my hosting
server, though they are using an older MySQL database vesion (4.1) with
PHP5, there are no problems. That's how I know it works. All that
remains is to fix this locally for WAMP.

Thanks.
Roland

petersprc@gmail.com
Guest
 
Posts: n/a
#4: Oct 24 '06

re: MySQL 4.1 / PHP 5.0 : Unicode problems


If you don't have that function, you could try sending this directly to
mysql:

SET NAMES UTF8

roland.saad@gmail.com wrote:
Quote:
Yes thanks!!! That did it! Wow, 4 days of debugging for this!
>
Thanks a lot.
>
However, i have a problem with my versions. I am running locally on
WAMP 1.6.3 and the function seems to be missing. However on my hosting
server, though they are using an older MySQL database vesion (4.1) with
PHP5, there are no problems. That's how I know it works. All that
remains is to fix this locally for WAMP.
>
Thanks.
Roland
Closed Thread