ID:              42297
 User updated by: bmilosavljevic at gmail dot com
 Reported By:     bmilosavljevic at gmail dot com
 Status:          Open
 Bug Type:        MySQL related
 PHP Version:     4.4.7
 New Comment:

I had the same problem with php 4.4.4 and MySQL server version of
4.1.22 standard on Linux server! Exactly, it is solved by this fix for
utf8 char set when database char set is utf8. What is your MySQl server
version? Maybe that's what matters.
Actually, by querying SET CHARACTER SET latin1 you did exactly the same
fix! It seems we should apply the same char set in this SQL statement as
in the database queried.
"Thus, is it possible
that PHP tries to convert any mysql results to utf8, even when neither
the database/tables, nor the PHP files are in utf8 ?" -> I think that
is exactly what MySQL tries to do. Only I am not sure why it can not
perform this conversion (according to this article at
http://www.bluetwanger.de/blog/2006/11/20/mysql-and-utf-8-no-more-question-marks/
-> I think you should see it)
I 'll test this on php 5.x.x and post the results...


Previous Comments:
------------------------------------------------------------------------

[2007-09-25 18:05:58] dev at unleashedmind dot com

The given fix works, if the database collation is utf8_* (f.e.
utf8_general_ci).

However, querying a database with collation latin1_* still returns
question marks instead of the actual characters. Thus, is it possible
that PHP tries to convert any mysql results to utf8, even when neither
the database/tables, nor the PHP files are in utf8 ?

I encounter this bug with PHP 4.4.7 on Windows (Server 2003). I'm not
able to reproduce it with PHP 4.4.7 on SuSE Linux. Also, this bug does
not seem to exist in PHP 5.

IIRC, my last installed version of PHP was 4.4.4, which did not have
this bug.

Strangely, if I add the rather senseless line
<?php
mysql_query('SET CHARACTER SET latin1', $link);
?>
immediately after the database connect, all mysql query read/write
results are fine.

------------------------------------------------------------------------

[2007-09-24 20:18:05] bmilosavljevic at gmail dot com

I think I 've found the solution! This bug is due to MySQL, I think. If
the following sql query is executed: SET CHARACTER SET utf8 (without ;
is recommended)
immediately after establishing a connection, the problem is solved, at
least for me! Even more suitable query would be SET NAMES utf8, because
connection's query strings are also submitted to the server in utf8.
<?php
$link = mysql_connect('localhost', 'database_username',
'database_user_pwd');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('database_name', $link)) {
echo 'Could not select database';
exit;
}

//could be also SET NAMES utf8
$sql = 'SET CHARACTER SET utf8';
$result = mysql_query($sql, $link);
...
?>
and instead of ... any query executed should return proper utf8
characters. Check this please in your environment!

------------------------------------------------------------------------

[2007-09-24 14:10:44] dev at unleashedmind dot com

Confirming that this bug exists.

------------------------------------------------------------------------

[2007-08-14 16:07:27] bmilosavljevic at gmail dot com

Description:
------------
mysql_fetch functions return question marks (?) instead of utf8 chars
(other than latin1). Tested on linux production server and on local
windows developer server as well.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42297&edit=1

Reply via email to