惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LangChain Blog
量子位
GbyAI
GbyAI
B
Blog RSS Feed
月光博客
月光博客
人人都是产品经理
人人都是产品经理
腾讯CDC
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The Cloudflare Blog
D
Docker
Cyberwarzone
Cyberwarzone
U
Unit 42
NISL@THU
NISL@THU
C
Check Point Blog
B
Blog
大猫的无限游戏
大猫的无限游戏
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
P
Proofpoint News Feed
F
Fortinet All Blogs
V
V2EX
T
Threat Research - Cisco Blogs
T
Threatpost
S
SegmentFault 最新的问题
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
TaoSecurity Blog
TaoSecurity Blog
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
P
Privacy International News Feed
L
Lohrmann on Cybersecurity
AWS News Blog
AWS News Blog
G
Google Developers Blog
美团技术团队

博客园 - xxp

翻译:Android程序开发入门 asp.net中使用ajax中的三种方式 翻译:xoops搜索功能的使用 发布新软件:史上最轻量级的ORM--EasyDBOperation XOOPS模块开发快速入门中文翻译--索引 XOOPS模块开发快速入门中文翻译(十) XOOPS模块开发快速入门中文翻译(九) XOOPS模块开发快速入门中文翻译(八) XOOPS模块开发快速入门中文翻译(七) XOOPS模块开发快速入门中文翻译(六) XOOPS模块开发快速入门中文翻译(五) XOOPS模块开发快速入门中文翻译(四) XOOPS模块开发快速入门中文翻译(三) XOOPS模块开发快速入门中文翻译(二) XOOPS模块开发快速入门中文翻译(一) 简单的网页内容采集器(C#) C#网络编程学习笔记1 100%男性倾向? 55 为什么? 学习XOOPS的记录
php,mysql下中文编码解决方案
xxp · 2009-03-08 · via 博客园 - xxp

文档:

sample enviroment:
it's not simle to yours but I think it will work.
windows server 2003 Simple Chinese edition
apache 2.2.11
php-5.2.8-Win32
MySQL-5.1.31
=============


0.编码选择:UTF-8 还是 GB2312还是GBK。
UTF-8可以兼容ASCII编码,会根据需要占用1个或者2个字节,比较小。(其他如UTF-16和UTF-32是固定死占用2个字节或者4个字节的)
GB2312只能包括6000多常用字
GBK可以包含简体、繁体,范围广

1. PHP中的设置
php中要对php.ini文件中设置开启extension=php_mbstring.dll,按照需要修改mb_string的相关编码配置
2.MySql中的设置:
因为mySql字符集的支持细化到四个层次: 服务器(server),数据库(database),数据表(table)和连接(connection)。因此可以后面再设置
3.Apache中的设置:
如果是UTF-8就不用设置,如果是GBK需要设置一下httpd.conf ,开启AddDefaultCharset
4.具体操作:
第一步:建立数据库
默认是latine的encoding和collection的。因为只有一个字段是中文的,所以不用修改数据库的默认配置文件。
只要建立数据库的时候,对这个字段设置为gbk_chinese_ci即可
第二步:设置网页的charset和encoding。如果是没有设置,将根据客户端的Request来
第三步,建立连接的时候需要
SET character_set_client='gbk'
SET character_set_connection='gbk'
SET character_set_results='gbk'
(这个配置就等价于 SET NAMES 'gbk'。


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

0.choose an encoding
you have 3 choises:utf-8,gb2312 and GBK.
UTF-8 contains ASKII, and it uses 1 or 2 bytes so it's smaller to transform in web.
but it's contains less Chinese Characters.(Others like UTF-16 and UTF-32,is fixed to user 2 or 4 bytes)
GB2312 contains only 6000 more popular characters, such as '***' can't be contained.
GBK contains simple Chinese and Tranditional Chinese ,I think it's pro. my sample is for GBK.


1. config PHP
modify php.ini , and set the line
extension=php_mbstring.dll
on
.maybe you need to configurate the mb_string.
2.mySql configration
as mySql supports defferent charset in 4 layers, the server, the database,the table and connection.
and you have only one table ,one field in Chinese, you need not to modify the whole mysql configration

3.Apache configuration
If you are willing to use UTF-8 , you need not to configurate anything for it support utf-8 by default.
if you want to use GBK you need to modify httpd.conf and open the AddDefaultCharset

4.sample steps:
firstly, create a database
and the database's collection is latine.
when you create the table, the field, set the field's collection to gbk_chinese_ci

secondly, set the special pages you want to show the Chinese Characters.
set the charset and encoding


third, when you build a connection ,either in commandline or php , you need to run the 3 lines script:

SET character_set_client='gbk'
SET character_set_connection='gbk'
SET character_set_results='gbk'

these three lines are equle to

 SET NAMES 'gbk'

例子:

php文件

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>测试中文入数据库</title>
</head>

<body>
<ul>
 <?php
 $conn = mysql_connect("localhost","root","sa");
mysql_query("set names 'gbk'");//关键是这句
mysql_select_db("test");
$sql = "select * from chinesetest ";
$result = mysql_query($sql,$conn);


while($row = mysql_fetch_assoc($result))
{
 echo  "<li>".$row['id']."-".$row["CF"]."</li>";
}

$sql2 = "Insert Into chinesetest (CF) values('中文插入测试');";
mysql_query($sql2);
$sql2 = "Insert Into chinesetest (CF) values('請看,這裡是繁體中文')";
//echo $sql2;
mysql_query($sql2);
echo mysql_error();

mysql_close();
?> 
</ul>
</body>
</html>
 整体解决方案:

/Files/xxpyeippx/chinese_on_mysql.zip

建表语句:

CREATE TABLE IF NOT EXISTS `chinesetest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `CF` varchar(255) CHARACTER SET gbk NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;