Php connection to mysql garbled solution

Source: Internet
Author: User
Many of my friends may encounter garbled characters when they connect to the database for reading or writing at the early stage of learning PHP. Today, I am here to tell you the simplest way to solve the garbled problem by using phpmyadmin to add a mysql database, then use php operations database garbled solution: 1: confirm phpmyadmin mysql character set for utf-8unicode (utf8) "> <LINKhref

Many of my friends may encounter garbled characters when they connect to the database for reading or writing at the early stage of learning PHP. Today, I am here to tell you the simplest way to solve the garbled problem.

 

Use phpmyadmin to add a mysql database, and then use php to operate the database. The solution is garbled:

1: confirm that the mysql character set used by phpmyadmin is UTF-8 unicode (utf8), the mysql connection is utf8_general_ci, and the language is chinese-chinese simplified.
2: confirm that each data table is "utf8_general_ci;
3: add a statement after connecting to the mysql database in php to specify the character set of the database,
Example: $ conn = mysql_connect ("localhost", "root", "your password"); // connect to the database
Mysql_query ("set name 'utf8 '");

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.