Heim  >  Artikel  >  Backend-Entwicklung  >  php 中文字符入库或显示乱码问题的解决方法_PHP

php 中文字符入库或显示乱码问题的解决方法_PHP

WBOY
WBOYOriginal
2016-06-01 12:19:54957Durchsuche

大家以后在编写过程中, 一定要记得定义字符类型。
mysql_query("set names 'gbk'")
解决的方法就这么简单。
今天做了一个数据库查询,放出代码。
复制代码 代码如下:
/*
filename:query.php
do:get and show the data
author:www.5dkx.com
*/
include_once("conn.php");
include_once("include.php");
mysql_query("set names 'gbk'")or die("设置字符库失败\n");
mysql_select_db($db)or die("连接数据库失败!\n");
$exec = "select * from $table";
//echo $exec;
$result = mysql_query($exec,$conn)or die("查询数据库失败\n");
echo "

";
for($cout=0;$cout{
$city = mysql_result($result,$cout,city);
$name = mysql_result($result,$cout,name);
$phone = mysql_result($result,$cout,phone);
echo "
";
echo "city: $city";
echo "name: $name";
echo "phone: $phone";
echo "";
}
echo "
";
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn