On May 17, 2008, at 12:44 AM, wesley wrote:

PHP function mysql_query & mysql_fetch_xxxxx cannot handle myltibyte column data.

I've test for resin version 3.1.5/3.1.6 and 3.2.0 snapshot, also mysql 4.1.22/5.0.51b/5.1.23rc/6.0.4/alpha as well as mysql-connector- java-3.1.14/5.1.x.
This issue can be reproduced in every combination.

Thanks. I've filed this as http://bugs.caucho.com/view.php?id=2676.

The solution may be a bit tricky because the JDBC driver normally handles i18n in Java, while PHP normally just deals with the unencoded bytes.

Have you checked the behavior with unicode.semantics="on"? (i.e. PHP 6 mode). If that's enabled, then Quercus strings are 16-bit like Java, not 8-bit like PHP 5. That may be more compatible with the JDBC driver (and really is the right direction moving forward.)

-- Scott



Test case:
============test.php============
<?PHP

//$db = mysql_connect("java:comp/env/jdbc/discuz"); // not ok either
$db = mysqli_connect('127.0.0.1', 'root', 'password', 'test');
mysqli_query($db, 'SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary;');
$query = mysqli_query($db, 'SELECT * FROM test');
while($test = mysqli_fetch_assoc($query)) {
echo $test['name']."\n";
}

$db = mysql_connect('localhost', 'root', 'password');
mysql_query('SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary;', $db);
mysql_select_db('test', $db);
$query = mysql_query('SELECT * FROM test', $db);
while($test = mysql_fetch_array($query, MYSQL_ASSOC)) {
echo $test['name']."\n";
}
?>
=================================

Output should be:
你好
我好
你好
我好


Output now was:
`}
}
`}
}

=============resin-web.xml===========
<web-app xmlns="http://caucho.com/ns/resin";>
<database>
<jndi-name>jdbc/discuz</jndi-name>
<driver type="com.mysql.jdbc.Driver">
<url>jdbc:mysql://localhost:3306/test? useUnicode=true&amp;characterEncoding=UTF-8</url>
 <!-- not ok either
 <url>jdbc:mysql://localhost:3306/test</url>
 -->
 <user>root</user>
 <password>password</password>
 <init-param characterEncoding="UTF-8" />
 <init-param useUnicode="true" />
</driver>
<max-connections>200</max-connections>
</database>

<servlet-mapping url-pattern="*.php"
servlet- class="com.caucho.quercus.servlet.QuercusServlet">
<init>
 <database>java:comp/env/jdbc/discuz</database>
 <script-encoding>UTF-8</script-encoding>
 <compile>false</compile>
 <php-ini>
  <unicode.runtime_encoding>UTF-8</unicode.runtime_encoding>
  <unicode.output_encoding>UTF-8</unicode.output_encoding>
 </php-ini>
</init>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.php</welcome-file>
</welcome-file-list>
</web-app>
=================================


============mysql db script===========
-- MySQL dump 10.13  Distrib 5.1.24-rc, for Win32 (ia32)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version 5.1.24-rc-community

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `test`
--

DROP TABLE IF EXISTS `test`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `test` (
`name` varchar(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `test`
--

LOCK TABLES `test` WRITE;
/*!40000 ALTER TABLE `test` DISABLE KEYS */;
INSERT INTO `test` VALUES (0xe4bda0e5a5bd);
INSERT INTO `test` VALUES (0xe68891e5a5bd);
/*!40000 ALTER TABLE `test` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET [EMAIL PROTECTED] */;

/*!40101 SET [EMAIL PROTECTED] */;
/*!40014 SET [EMAIL PROTECTED] */;
/*!40014 SET [EMAIL PROTECTED] */;
/*!40101 SET [EMAIL PROTECTED] */;
/*!40101 SET [EMAIL PROTECTED] */;
/*!40101 SET [EMAIL PROTECTED] */;
/*!40111 SET [EMAIL PROTECTED] */;

-- Dump completed on 2008-05-17  6:35:33

=================================

-Wesley


_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest



_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to