ID: 42297 Comment by: dev at unleashedmind dot com Reported By: bmilosavljevic at gmail dot com Status: Open Bug Type: MySQL related PHP Version: 4.4.7 New Comment:
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. Previous Comments: ------------------------------------------------------------------------ [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