首页 > php教程 > php手册 > 正文

php,mysql下中文编码解决方案

php中文网
发布: 2016-06-06 19:48:20
原创
1078人浏览过

文档: 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编码,

文档:

 

php商城系统
php商城系统

PHP商城系统是国内功能优秀的网上商城系统,同时也是一个商业的PHP开发框架,有多套免费模版,强大的后台管理功能,专业的网上商城系统解决方案,快速建设网上购物商城、数码商城、手机商城、办公用品商城等网站。 php商城系统v3.0 rc6升级 1、主要修复用户使用中出现的js未加载完报错问题,后台整改、以及后台栏目的全新部署、更利于用户体验。 2、扩展出,更多系统内部的功能,以便用户能够迅速找到需

php商城系统 0
查看详情 php商城系统

立即学习PHP免费学习笔记(深入)”;

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免费学习笔记(深入)”;

 

立即学习PHP免费学习笔记(深入)”;

 

立即学习PHP免费学习笔记(深入)”;

例子:

 

立即学习PHP免费学习笔记(深入)”;

php文件

 

立即学习PHP免费学习笔记(深入)”;




娴嬭瘯涓
相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号