We look forward to your help. Niu X is here. PHP inserts mysql garbled characters and is set up. the solution is still unavailable.

Source: Internet
Author: User
We look forward to your help. you will be here. PHP inserts mysql garbled characters and is set up. it is still not possible to insert PHP into mysql. The data from the terminal to phpmyadmin browsing is garbled. you can help analyze the environment: the LAMP1.mysql encoding settings are as follows: mysql & gt; showvariableslike is coming soon for your help. you can just try again. PHP inserts mysql garbled characters.
Data inserted from PHP to mysql is garbled from the terminal to phpmyadmin.
Environment: LAMP

1. mysql encoding settings are as follows:

Mysql> show variables like 'character _ set _ % ';
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
8 rows in set (0.00 sec)

2. mysql global settings are as follows:
/Etc/my. cnf

Default-character-set = 'utf8'

Default-character-set = 'utf8'
3. PHP connection encoding settings are as follows:

Function db_connect ()

$ Result = new mysqli ('IP', 'DB', 'user', 'passwd ');
Mysql_query ("set names 'utf8 '");

4. PHP page encoding settings are as follows:

You can set all the settings. why are there still garbled characters in phpmyadmin and terminal !!!!!
PS: phpmyadmin and the terminal also set the encoding to UTF8

Which of the following can help solve the problem. Thank you!

------ Solution --------------------
Mysql uses UTF-8 when setting utf8.

Garbled code solution requires step-by-step debugging/observation

First, check your page code and the encoding format used by the browser when opening your page ..
Then, print the data you submitted from $ _ POST, $ _ GET, and check whether there is a problem with the encoding when the front-end transmits the data to the background.
Then, check before writing data to the database ..
Then, determine the encoding of the database. this usually changes the correct client to write data to the database to check the database performance ..
------ Solution --------------------
Page is UTF-8
Be sure not to make a mistake.
In addition, the web page can not be set, as long as the program code is a UTF-8.
------ Solution --------------------

Save EditPlus 3 as UTF-8.

Mysql connection: mysql_query ('set names utf8 ');

------ Solution --------------------
Thank you for your help. I used mysqli to connect to the database. when I used mysqli, mysql_query ("set names 'utf8'"); I don't know why it didn't work. I have no problem with the following:
$ Result = new mysqli ('localhost', 'root', '', 'DB ');
$ Result-> query ("set names 'utf8 '");

Ask your friends to answer $ result-> qu ......

------ Solution --------------------

I. All utf8 files are replaced with UTF-8.

II. mysql_query ("set names 'utf8'"); changed to: mysql_query ("set names 'utf-8 '");
Pay attention to punctuation marks, which are quotation marks rather than single quotation marks.

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.