广告联盟网

标题: MYSQL中文乱码如何处理? [打印本页]

作者: mjoshua    时间: 2007-7-14
标题: MYSQL中文乱码如何处理?
`name` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,<br />`code` VARCHAR( 6 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,<br />`cat` VARCHAR( 1 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL)&quot;;<br /><br />`name` VARCHAR( 20 ) CHARACTER SET utf8 NOT NULL,<br />`code` VARCHAR( 6 ) CHARACTER SET utf8 NOT NULL ,<br />`cat` VARCHAR( 1 ) CHARACTER SET utf8 NOT NULL)&quot;;<br /><br /><br />`name` VARCHAR( 20 ) CHARACTER SET gb2312 NOT NULL,<br />`code` VARCHAR( 6 ) CHARACTER SET gb2312 NOT NULL ,<br />`cat` VARCHAR( 1 ) CHARACTER SET gb2312 NOT NULL)&quot;;<br /><br />都不行啊 <br /><br />帮帮忙谢谢<br /><br />`name` VARCHAR( 20 ) CHARACTER SET gb2312 COLLATE gb2312_bin NOT NULL,<br />`code` VARCHAR( 6 ) CHARACTER SET gb2312 COLLATE gb2312_bin NOT NULL ,<br />`cat` VARCHAR( 1 ) CHARACTER SET gb2312 COLLATE gb2312_bin NOT NULL)&quot;;<br /><br />不行<br /><br />[<i> 本帖最后由 mjoshua 于 2007-7-14 20:55 编辑 </i>]
作者: 网鬼    时间: 2007-7-14
连接数据后执行mysql_query(&quot;set names utf8&quot;);
作者: mjoshua    时间: 2007-7-14
<br><br><div class="msgbody"><div class="msgheader">QUOTE:</div><div class="msgborder">原帖由 <i>网鬼</i> 于 2007-7-14 20:52 发表 <a href="http://www.im286.com/redirect.php?goto=findpost&amp;pid=20547185&amp;ptid=2067129" target="_blank"><img src="http://www.im286.com/images/common/back.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.im286.com/images/common/back.gif');}" onmousewheel="return imgzoom(this);" alt="" /></a><br />连接数据后执行mysql_query(&quot;set names utf8&quot;); </div></div><br>这有什么用?我直接在创建的时候,就指定name 为uft8了<br />都不行,连接之后再指定
作者: yangbo254    时间: 2007-7-14
在输出页面直接强制使用UFT-8编码
作者: mjoshua    时间: 2007-7-14
可是我要拿数据库里面的字符串还要进行一些对比,乱码,没法对比啊<br />还有就是用了binary数据类型之后,在数据库里显示是中文,可是明明视觉上是相同的字,它对比的就是错误
作者: 暖月    时间: 2007-7-14
技术贴。两种方法<br />@mysql_query(&quot;set names 'gbk'&quot;); <br /><br />iconv($str,'gbk','utf8')
作者: yangbo254    时间: 2007-7-14
<br><br><div class="msgbody"><div class="msgheader">QUOTE:</div><div class="msgborder">原帖由 <i>mjoshua</i> 于 2007-7-14 21:03 发表 <a href="http://www.im286.com/redirect.php?goto=findpost&amp;pid=20547333&amp;ptid=2067129" target="_blank"><img src="http://www.im286.com/images/common/back.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.im286.com/images/common/back.gif');}" onmousewheel="return imgzoom(this);" alt="" /></a><br />可是我要拿数据库里面的字符串还要进行一些对比,乱码,没法对比啊<br />还有就是用了binary数据类型之后,在数据库里显示是中文,可是明明视觉上是相同的字,它对比的就是错误 </div></div><br><img src="images/smilies/ohh.gif" smilieid="19" border="0" alt="" /> 谁喊你用binary数据类型啊~~该惨(风凉话)
作者: 呼唤    时间: 2007-7-14

作者: mjoshua    时间: 2007-7-14
对了,这是采集中文页面碰到的问题,要怎么处理这些?刚学PHP
作者: mjoshua    时间: 2007-7-14
<br><br><div class="msgbody"><div class="msgheader">QUOTE:</div><div class="msgborder">原帖由 <i>yangbo254</i> 于 2007-7-14 21:08 发表 <a href="http://www.im286.com/redirect.php?goto=findpost&amp;pid=20547430&amp;ptid=2067129" target="_blank"><img src="http://www.im286.com/images/common/back.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.im286.com/images/common/back.gif');}" onmousewheel="return imgzoom(this);" alt="" /></a><br /><br /><img src="images/smilies/ohh.gif" smilieid="19" border="0" alt="" /> 谁喊你用binary数据类型啊~~该惨(风凉话) </div></div><br>在网上找中文乱码处理方法的时候看到的
作者: mjoshua    时间: 2007-7-14
<br><br><div class="msgbody"><div class="msgheader">QUOTE:</div><div class="msgborder">原帖由 <i>暖月</i> 于 2007-7-14 21:08 发表 <a href="http://www.im286.com/redirect.php?goto=findpost&amp;pid=20547419&amp;ptid=2067129" target="_blank"><img src="http://www.im286.com/images/common/back.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.im286.com/images/common/back.gif');}" onmousewheel="return imgzoom(this);" alt="" /></a><br />技术贴。两种方法<br />@mysql_query(&quot;set names 'gbk'&quot;); <br /><br />iconv($str,'gbk','utf8') </div></div><br>用了<br />$name=iconv(&quot;gb2312&quot;,&quot;utf-8&quot;,$name); <br />可以正常保存为中文了,往下再谢谢看<br /><br />先谢谢大家了
作者: lzcpcnet    时间: 2007-7-14
好帖<br />不要沉,顶起。
作者: mjoshua    时间: 2007-7-14
用了<br />可以显示中文之后,可是还是有些中文转不过来,变空了<br />之前我用$name=str_replace(&quot;A&quot;,&quot;A&quot;,$name);<br />替换相似的全角字符之后,再用<br />$name=iconv(&quot;gb2312&quot;,&quot;utf-8&quot;,$name);<br />之前就些字符为空了,<br />可是先用<br />$name=iconv(&quot;gb2312&quot;,&quot;utf-8&quot;,$name);<br /><br />再用<br />$name=str_replace(&quot;A&quot;,&quot;A&quot;,$name);<br />就替换不了全角之符<br /><br />那用了iconv之后怎么替换全角字符?
作者: 暖月    时间: 2007-7-14
不知道了。。。好久没摸过了!!!!!呵呵!
作者: mjoshua    时间: 2007-7-14
呵呵,看来又得找找了
作者: 暖月    时间: 2007-7-14
@mysql_query(&quot;set names 'gbk'&quot;); <br /><br />可以查一下用法,这个是可以保留全角的。




欢迎光临 广告联盟网 (https://bbs.ggads.com/) Powered by Discuz! X3.2