Character encoding during phpselect query, Require ("db. php ");
$ SQL = "SELECT 'cityid' FROM 'weather cityid' 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 replace Guangdong with a number or a character, you can succeed. what is the problem?
Reply to discussion (solution)
What code is your program?
What is the encoding of your city field?
The following are several possible cases:
1. The program is gbk, and the city is utf8. before the query, mysql_query (/set names gbk ');
2. The program is UTF-8 and the city is gbk. before the query, mysql_query (/set names utf8 ');
3. Worst case: The city is not encoded and the program is UTF-8
In this case
$ W = iconv ('utf-8', 'latin1', 'Guangdong ');
$ SQL = "SELECT 'cityid' FROM 'weather cityid' where 'city' = '$ w '";
The retrieved data must be unencoded.
Didn't you output This? why didn't you succeed?
The question of the landlord is very profound.
Save the file as UTF-8, and set mysql_query ('set names utf8') during mysql Query ');
Mysql cannot identify the encoding, so it cannot be found