php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jhala at uoregon dot edu
New email:
PHP Version: OS:

 

 [2007-07-10 21:41 UTC] jhala at uoregon dot edu
Description:
------------
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);
mysql_set_charset("utf8");

$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".

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-10 21:51 UTC] sniper@php.net
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 http://www.php.net/support.php 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] tony2001@php.net
Not PHP problem.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Nov 26 15:05:54 2022 UTC