Is there a utf8 bug with mysql_fetch_array()

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
zebra
Forum Newbie
Posts: 3
Joined: Sun Feb 04, 2007 9:18 pm

Is there a utf8 bug with mysql_fetch_array()

Post by zebra »

I am using MySQL 4.1.22. and PHP 4.4.4.

Now, when I add the following 2 lines of code, mysql_query() works perfectly with utf8 charset:
mysql_query("SET CHARACTER SET utf8", $db);
mysql_query("SET NAMES 'utf8'", $db);




However, results for mysql_fetch_array() appears like (????????).



I'd search google for a solution but was unable to find one. If it is really a bug with mysql_fetch_array(), how can I rewrite mysql_fetch_array() to use mysql_query() instead?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are your pages telling the browser they are outputting utf8 streams?
zebra
Forum Newbie
Posts: 3
Joined: Sun Feb 04, 2007 9:18 pm

Post by zebra »

Yes,
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
is declared and mysql_query() works perfectly.

Thanks for your assistance.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

So you're not calling header() with a content type?
zebra
Forum Newbie
Posts: 3
Joined: Sun Feb 04, 2007 9:18 pm

Post by zebra »

No, I wasn't using header. But I added header('Content-Type: text/html; charset=UTF-8'); like you suggested.

The result is still ???? for mysql_fetch_array().
but works perfectly for mysql_query()
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

MySql 4 isn't that great on UTF8 support. You may not have the approriate character installed for MySql to store and retrieve the data properly.

http://dev.mysql.com/doc/refman/4.1/en/ ... ation.html

MySql 5 remedied this problem has very robust UTF8 support. If you can upgrade your server you should.
Post Reply