|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-11-10 16:36 UTC] lzx21cn at 21cn dot com
Description: ------------ write in mysql by utf8 it is wrong! Reproduce code: --------------- 1.modify php.ini ... mbstring.internal_encoding = UTF-8 mbstring.http_output = UTF-8 mbstring.detect_order = UTF-8 2. php file (utf8) $sql="insert into test1 values(2,'四大皆空');"; mysql_query($sql); Expected result: ---------------- *record where id=1 is inputed in gnome-terminal ---- command: mysql IN gnome-terminal (utf8) ---- select * from test1; id | name 1 | 皆大欢喜 2 | 四大皆空 -------------------------------------------------- Actual result: -------------- ---- command: mysql IN gnome-terminal (utf8) ---- select * from test1; id | name 1 | 皆大欢喜 2 | (something character which I unknow) -------------------------------------------------- PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
you need php file (utf8) ---------------------- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php $connect=mysql_connect("localhost","kevin",""); $select=mysql_select_db("kevin",$connect); $query="insert into test1 values (2,\"四大皆空\");"; $result=mysql_query($query); $result=mysql_query("select * from test1;"); $rows=mysql_num_rows($result); for ($i=0;$i<$rows;$i++) { $a=mysql_fetch_array($result); echo "第一个字段是:".$a[0]." | "; echo "第二个字段是:".$a[1]."<br>"; } mysql_close(); ?>sorry, 1st comment file is error This is you need php file (utf8) ---------------------- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php $connect=mysql_connect("localhost","kevin",""); $select=mysql_select_db("kevin",$connect); $query="insert into test1 values (2,\"四大皆空\");"; $result=mysql_query($query); $result=mysql_query("select * from test1;"); mysql_close(); ?>can't repeat (tested with MySQL 4.1 and 5.0): <?php $connect=mysql_connect("localhost","phptest","php"); $select=mysql_select_db("test",$connect); /* create test table */ mysql_query("DROP TABLE IF EXISTS test_35183"); mysql_query("CREATE TABLE test_35183 (a varchar(20) character set utf8)"); /* set client connection to utf8 */ mysql_query("SET NAMES utf8"); $expected = "四大皆空"; $query="insert into test1 values ('$expected')"; $result=mysql_query($query); if (($result=mysql_query("select a from test_35183"))) { $row=mysql_fetch_row($result); printf("Expected: %s Returned: %s\n", $expected, $row[0]); } mysql_query("DROP TABLE test_35183"); mysql_free_result($result); mysql_close(); ?> Output: Expected: 四大皆空 Returned: 四大皆空php file must inclue this line <?php /* set client connection to utf8 */ mysql_query("SET NAMES utf8"); ?> Thank you very much!