Character encoding disposition when PHP select query

Source: Internet
Author: User
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.
  • Related Article

    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.