Rumah > Artikel > pembangunan bahagian belakang > 请教这个PHP调用的MYSQL数据为什么乱码了
请问这个PHP调用的MYSQL数据为什么乱码了?
function writeStatistic($sql,$txt_name){<br /> $filename="".$txt_name;//注意修改文件的路径<br /> if (file_exists($filename)) {<br /> $fp=fopen($filename,"a+");<br /> }else{<br /> $fp=fopen($filename,"w+");<br /> }<br /><br /> $text=$sql."\r\n";<br /> fwrite($fp,$text);<br /> fclose($fp);<br />}<br />/**<br />* 向指定文件写入字符集设置句柄<br />*<br />* 参数: string $txt_name : 指定文件名<br />* 返回: void<br />* 作用域: public<br />*/<br />function writeStatistic_set_name($txt_name){<br /> $set_name="<?xml version=\"1.0\" encoding=\"utf-8\"?><br /><urlset>";<br /> //转化为utf-8编码<br /> <br /> $filename="".$txt_name;//注意修改文件的路径<br /> if (file_exists($filename)) {<br /> unlink($filename);<br /> $fp=fopen($filename,"a+");<br /> }else{<br /> $fp=fopen($filename,"w+");<br /> }<br /><br /> $text=$set_name."\r\n";<br /> fwrite($fp,$text);<br /> fclose($fp);<br />}<br />$nowDate = date("Y-m-d");<br />$txt_name='sitemap.xml';<br />writeStatistic_set_name($txt_name);<br />$sql="select * from jieqi_article_article ORDER BY lastupdate DESC";<br />$db->query($sql);<br />for($i=1;$i<= $db->num_rows();$i++){<br /> $db->next_record();<br /> $siteid = $db->f(siteid);<br /> $haha = _;<br /> $articleid = $db->f(articleid);<br /> $newname = $db->f(articlename);<br /> $newid = $db->f(lastchapterid);<br /> $nowDate = $db ->f(lastupdate);<br /> $nowDate = date("Y-m-d H:m:s",$nowDate);<br /> $url = "<br /> <url><br /> <loc>http://www.1.org/html/$articleid/$newid.html </loc><br /> <lastmod>$nowDate</lastmod><br /> <changefreq>always</changefreq><br /> <priority>1.0</priority><br /> <name>$newname</name><br /> </url>";<br /> //转化为utf-8编码<br /> $url = utf8_encode($url);<br /> writeStatistic($url,$txt_name);<br />}<br />$db->free();<br />$over='</urlset>';<br />writeStatistic($over,$txt_name);<br />print "Google Sitemap生成结束!<br/><a href='sitemap.xml' target='_blank'>点击这里查看</a>";<br />exit;<br />?>