如何将数据库中的GB2312编码转换成utf-8编码
来源:互联网 发布:数据建模分析 工具 编辑:程序博客网 时间:2024/05/02 07:55
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
$dbhost="localhost";
$dbuser="root";
$dbpassword = "";
$dbname="2012";
$icen_news_archives1="icen_news_archives1";
mysql_connect($dbhost,$dbuser,$dbpassword) or die("数据库出了点小问题,对不起!请稍后访问......");
mysql_select_db($dbname) or die("数据库现在繁忙,请稍后访问......");
$sql="select * from $icen_news_archives1";
$query=mysql_query($sql);
/*----------------------先把数据库中的原来的数据读出来--------------------------*/
while($records=mysql_fetch_array($query, MYSQL_ASSOC))
{
$cid=$records['cid'];
$authorName=$records['authorName'];
$nTime=$records['nTime'];
$nCount=$records['nCount'];
$nTitle=$records['nTitle'];
$isTitleBold=$records['isTitleBold'];
$cid=iconv("GB2312", "UTF-8", "$cid"); // 转换编码
$authorName=iconv("GB2312", "UTF-8", "$authorName");
$nTime=iconv("GB2312", "UTF-8", "$nTime");
$nCount=iconv("GB2312", "UTF-8", "$nCount");
$nTitle=iconv("GB2312", "UTF-8", "$nTitle");
$isTitleBold=iconv("GB2312", "UTF-8", "$isTitleBold");
mysql_query("set names utf8");//转换字符集
$sql1="insert into icen_news_archives (nid,cid,authorName,nTime,nCount,nTitle,isTitleBold)values(NULL, '$cid', '$authorName', '$nTime', '$nCount', '$nTitle', '$isTitleBold')"; // 把转换后的结果一条条插入新库,这样也会防止数据丢失
$query1=mysql_query($sql1);
if($query1)
{
echo "1";
}else{
echo "0";
}
}
?>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
$dbhost="localhost";
$dbuser="root";
$dbpassword = "";
$dbname="2012";
$icen_news_archives1="icen_news_archives1";
mysql_connect($dbhost,$dbuser,$dbpassword) or die("数据库出了点小问题,对不起!请稍后访问......");
mysql_select_db($dbname) or die("数据库现在繁忙,请稍后访问......");
$sql="select * from $icen_news_archives1";
$query=mysql_query($sql);
/*----------------------先把数据库中的原来的数据读出来--------------------------*/
while($records=mysql_fetch_array($query, MYSQL_ASSOC))
{
$cid=$records['cid'];
$authorName=$records['authorName'];
$nTime=$records['nTime'];
$nCount=$records['nCount'];
$nTitle=$records['nTitle'];
$isTitleBold=$records['isTitleBold'];
$cid=iconv("GB2312", "UTF-8", "$cid"); // 转换编码
$authorName=iconv("GB2312", "UTF-8", "$authorName");
$nTime=iconv("GB2312", "UTF-8", "$nTime");
$nCount=iconv("GB2312", "UTF-8", "$nCount");
$nTitle=iconv("GB2312", "UTF-8", "$nTitle");
$isTitleBold=iconv("GB2312", "UTF-8", "$isTitleBold");
mysql_query("set names utf8");//转换字符集
$sql1="insert into icen_news_archives (nid,cid,authorName,nTime,nCount,nTitle,isTitleBold)values(NULL, '$cid', '$authorName', '$nTime', '$nCount', '$nTitle', '$isTitleBold')"; // 把转换后的结果一条条插入新库,这样也会防止数据丢失
$query1=mysql_query($sql1);
if($query1)
{
echo "1";
}else{
echo "0";
}
}
?>
</body>
</html>
- 如何将数据库中的GB2312编码转换成utf-8编码
- 编码转换utf-8/gb2312
- 将文本文件中的字符编码从GB2312转换成为UTF-8,包括子目录中的文件
- 将文本文件中的字符编码从GB2312转换成为UTF-8,包括子目录中的文件
- 【转】将文本文件中的字符编码从GB2312转换成为UTF-8,包括子目录中的文件
- gb2312与utf-8网页编码转换
- PERL GB2312 UTF-8 编码转换
- C++转换unicode utf-8 gb2312编码
- 【Java】编码转换:UTF-8转GB2312
- 字符编码——在python2中如何将txt中的utf-8转换成中文
- Windows Phone 7 中将Gb2312编码转换成UTF-8
- Windows Phone 7 中将Gb2312编码转换成UTF-8
- javascript 将gb2312编码转utf-8编码
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?(...
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?
- JVM调优总结(九):新一代的垃圾回收算法
- Android 模拟器不能上网问题
- Android Bluetooth
- OpenCV - Mat、CvMat、IplImage类型浅析
- 如何解决企业IT架构难题
- 如何将数据库中的GB2312编码转换成utf-8编码
- 一种提取shellcode的方法
- WPF 自带Datagrid编辑后无法更新数据源的问题
- 个人成长的15种能力
- 一些产品的思路-张小龙分享
- 3、各种OP放大器选型手册
- vector/list/map
- SerializationException: 在分析完成之前就遇到流结尾
- LDO和DCDC电源的区别 .