The solution to the problem of storing or displaying garbled characters in PHP
- 2020-03-31 20:30:53
- OfStack
You must remember to define the character type later in the writing process.
Mysql_query (" set names' GBK ')"
The solution is as simple as that.
Today, I did a database query and released the code.
Mysql_query (" set names' GBK ')"
The solution is as simple as that.
Today, I did a database query and released the code.
<?php
include_once("conn.php");
include_once("include.php");
mysql_query("set names 'gbk'")or die(" Setting the character library failed n");
mysql_select_db($db)or die(" Database connection failed !n");
$exec = "select * from $table";
//echo $exec;
$result = mysql_query($exec,$conn)or die(" Query database failed n");
echo "<table border=2>";
for($cout=0;$cout<mysql_numrows($result);$cout++)
{
$city = mysql_result($result,$cout,city);
$name = mysql_result($result,$cout,name);
$phone = mysql_result($result,$cout,phone);
echo "<tr>";
echo "city: $city";
echo "name: $name";
echo "phone: $phone";
echo "</tr>";
}
echo "</table>";
?>