PHP select query, character encoding processing,
Require ("db.php");
$sql = "Select ' Cityid ' from ' Weathercityid ' where ' city ' = ' Guangdong '";
$result =mysql_query ($sql);
Var_dump ($result);
$a _city=mysql_fetch_array ($result);
Print_r ($a _city);
?>
The output result is
Guangdong
Resource (5, MySQL result)
If you change Guangdong to a number is a character can be successful, this is what? Select Iconv
Share to: more
------Solution--------------------
What code is your program?
What is the code of your city field?
Here are a few possible scenarios
1, the procedure is GBK, the city is UTF8 needs in the inquiry before mysql_query (/set names GBK ');
2, the procedure is Utf-8, the city is GBK needs in the inquiry before mysql_query (/set names UTF8 ');
3, the worst case: City does not set the code, and the program is Utf-8
This is required
$w = Iconv (' utf-8 ', ' latin1 ', ' Guangdong ');
$sql = "Select ' Cityid ' from ' Weathercityid ' where ' city ' = ' $w '";
The retrieved data also needs to be deserialized
------Solution--------------------
You're not outputting it, are you?
------Solution--------------------
Landlord problem, said very abstruse ah.
------Solution--------------------
Save the file as a utf-8,mysql query when set mysql_query (' Set names UTF8 ');
MySQL can't identify the code, so I can't find it.