The issue of TP frame and PDO character encoding

Source: Internet
Author: User

If the frame is inserted in Chinese and the view is not garbled    if the Chinese is inserted and queried with PDO will not be garbled    but the frame view PDO inserted Chinese will be garbled    Using the PDO output to see the TP inserted in Chinese will also be garbled    why is this? If you insert Chinese words directly in the MySQL black window    Use the frame to see the Chinese is not garbled   with PDO will be garbled    my PDO added this sentence also don't use Ah  header (' Content-type : Text/html;charset=utf-8; ');       
I changed   character encoding    was blind    later I looked at the character encoding of the table      Discover why the field is UFT8 format    table is GBK format? Like this situation how to let the framework and PDO way query Chinese talent is not garbled? Does the encoding of a field have anything to do with the encoding of the table? Which one is the most accurate?
This is the current character encoding for MySQL

 CREATE TABLE `user` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `age` int(15) NOT NULL,  `class` varchar(400) CHARACTER SET utf8 DEFAULT NULL,  `name` varchar(12) CHARACTER SET utf8 DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=390 DEFAULT CHARSET=gbk |

Reply content:

If the frame is inserted in Chinese and the view is not garbled    if the Chinese is inserted and queried with PDO will not be garbled    but the frame view PDO inserted Chinese will be garbled    Using the PDO output to see the TP inserted in Chinese will also be garbled    why is this? If you insert Chinese words directly in the MySQL black window    Use the frame to see the Chinese is not garbled   with PDO will be garbled    my PDO added this sentence also don't use Ah  header (' Content-type : Text/html;charset=utf-8; ');       
I changed   character encoding    was blind    later I looked at the character encoding of the table      Discover why the field is UFT8 format    table is GBK format? Like this situation how to let the framework and PDO way query Chinese talent is not garbled? Does the encoding of a field have anything to do with the encoding of the table? Which one is the most accurate?
This is the current character encoding for MySQL

 CREATE TABLE `user` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `age` int(15) NOT NULL,  `class` varchar(400) CHARACTER SET utf8 DEFAULT NULL,  `name` varchar(12) CHARACTER SET utf8 DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=390 DEFAULT CHARSET=gbk |

The TP framework uses the UTF8 format, so you must be the database character set is also a problem, you need to set the database to UTF8, the table needs to be set to UTF8 can be
You see the SQL code above, the field is UTF8, the table is GBK, there must be a problem

 CREATE TABLE `user` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `age` int(15) NOT NULL,  `class` varchar(400) CHARACTER SET utf8 DEFAULT NULL,  `name` varchar(12) CHARACTER SET utf8 DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=390 DEFAULT CHARSET=utf8 |
ALTER DATABASE 数据库名 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

Do not tangle, unified the entire project involved in the coding of the place are set to UTF8 will not appear garbled problem

  • 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.