|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41957 utf8 data appears to become ascii after mysql_query/mysql_fetch_row
Submitted: 2007-07-10 21:41 UTC Modified: 2007-07-12 09:00 UTC
From: jhala at uoregon dot edu Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.2.3 OS: Vista/Fedora 7/WinXP
Private report: No CVE-ID: None
 [2007-07-10 21:41 UTC] jhala at uoregon dot edu
I have a fully UTF-8 MySQL database with a fully UTF-8 table. I have a php page which has "<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />" at the top of the html section and "mysql_set_charset("utf8");" after my connection.  I have all my php.ini mbstring stuff configured for utf-8:

mbstring.language = Neutral
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.encoding_translation = On
mbstring.detect_order = auto

and for what it's worth, echo mb_internal_encoding(); reports "UTF-8" and mysql_client_encoding(); reports "utf8".

Reproduce code:
$con = mysql_connect('localhost', 'user', 'password');
mysql_select_db("database", $con);

$query = "SELECT japanese_terms.term_lang, language_en FROM japanese_terms, languages ";
$query .="WHERE japanese_terms.term_id = languages.language_id ORDER BY term_id";
$result = mysql_query($query);
while( $row = mysql_fetch_row($result))
  foreach($row as $field)
    { print($field . "<br />"); }

Expected result:
I expect the UTF-8 data to display properly, and as UTF-8 data.  When I run the same query that pulls out (in this case, Japanese, but say any) UTF8 data, it displays properly in MySQL Query Browser.

Actual result:
With php in the above context however, it does not.  Instead, it prints a ? corresponding to each character.  When I use mb_detect_encoding(); on each such string, it tells me they are encoded as "ASCII" instead of expected "UTF-8".


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-10 21:51 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

 [2007-07-12 07:00 UTC] jhala at uoregon dot edu
I beg to differ.  I have eliminated all other possible explanations.  The only remaining explanation, however improbable, is that this is a bug.  If you think I'm wrong, have me try something new.  I have googled and posted everywhere I can think, and nobody has a solution that I have not seen or tried.
 [2007-07-12 09:00 UTC]
Not PHP problem.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Dec 05 20:01:30 2023 UTC