Taobaodo's title must be long before someone can see it!

Source: Internet
Author: User
Daniel said that the title must be long before someone can see it !!!!!!!!!!!!!!! Okay, I'm a newbie! Chinese characters are always garbled during database preparation today! According to the online statement, database, data table, fields are unified encoding UTF-8, and the web page is also set up a charsetutf-8, and the browser shows other Chinese is no problem, is the display of all the items in the database? Finally, I added @ mysql_query (& quot; SETNAM Daniel, saying that the title must be long before someone can see it !!!!!!!!!!!!!!!

Okay, I'm a newbie!

Chinese characters are always garbled during database preparation today! According to the Internet, databases, data tables, and fields are all encoded in UTF-8, and charset = utf-8 is also set in the webpage, and it is no problem for the browser to display other Chinese characters, is the display of all the items in the database? Finally, I added @ mysql_query ("SET NAMES 'utf8'") to solve the problem!

Question !!!

Does this need to be added to every database operation? Is there any better way to make it painless and permanent?

By the way, I use phpmyadmin and mysql...

Ask the experts !!!

------ Solution --------------------
Of course you can. you only need to select the encoding you need when installing mysql.

Since it is a database, it is certainly used for everyone.
But must people have the same requirements as you?
------ Solution --------------------
You don't need to add them every time. you just need to add the sentence after mysql_select_db () is selected.
------ Solution --------------------
Discussion

You don't need to add them every time. you just need to add the sentence after mysql_select_db () is selected.

------ Solution --------------------
Modify the my. ini file
Add the following in [client:
Default-character-set = utf8
------ Solution --------------------
Modify the database configuration file my. ini.
------ Solution --------------------
Write a connection class and only call the method at a time:
Http://topic.csdn.net/u/20120415/21/d385678f-cbd1-4b83-b3de-5effe73db8ee.html? 18960
------ Solution --------------------
Yes. every time php connects to mysql, it notifies mysql of the encoding used for interaction.
You do not need to repeatedly notify mysql every time before mysql_query.
------ Solution --------------------
All DB classes are written in the project. you only need to call the method and pass the parameters. You do not need to write mysql_query ("set names 'utf8'") by yourself '");

------ Solution --------------------
Write a class mysql class and set the encoding in the class,
It is good to instantiate the mysql class every time the location Library is located.

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.