Character encoding during phpselect query,

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.