您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php连接数据库乱码

2025/9/30 0:44:30发布16次查看
要解决php数据库乱码问题可以做以下设置:
1、数据库里的设置:
(1)在mysql中新建数据库的时候数据库选择utf-8编码既字符集设定为 utf-8_unicode_ci(unicode (多语言), 不区分大小写),库里面表table的整理设置为utf-8_general_ci;表里面的每个字段的 整理 都设置为utf-8_general_ci。
(2)创建数据库时,规定字符类型为uft8,如:
create database db_name character set utf8;
或修改已创建数据库成utf8类型:
alter database db_name character set utf8;
(3)创建表时,规定字符类型为utf8,如:
create table tb_name( id int(10) not null auto_increment, username char(34) not null , password int(56) not null, primary key (id) ) default charset=utf8;
或修改已创建表为utf8格式:
alter table tb_name character set utf8;
或修改表中某个字段为utf8格式
alter table tb_name modify type_name varchar(50) character set utf8;
2、php连接时的设置,在php的mysql连接函数中,加上语句:
//注意此处为utf8,不要写成utf-8mysql_query("set names 'utf8'");
3、网页页面申明编码
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
4、浏览器设置为utf-8格式。
5、编辑器字符编码,代码文档要保存为utf-8格式。
6、若插入数据乱码,可以对插入数据进行转码。先把字符串转为utf-8再插入数据库中。
推荐教程:php视频教程
以上就是php连接数据库乱码的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product