Home > Database > Mysql Tutorial > Detailed explanation of mysql query character set mismatch problem

Detailed explanation of mysql query character set mismatch problem

小云云
Release: 2017-12-22 14:42:46
Original
1896 people have browsed it

This article mainly introduces to you the solution to the problem of mysql query character set mismatch. The article introduces it to you in great detail through sample code. It has certain reference and learning value for friends who also encounter this problem. It is necessary Friends, please follow the editor to learn together. I hope it can help everyone.

Sometimes the MySQL database uses the latin character set when creating tables, and the query on the web page is utf-8. When Chinese is entered on the input page and then queried in the database, it will be reported ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' This error, so I found this database in the stackover flow and changed the character set in the data table Methods.


SET collation_connection = 'utf8_general_ci'
Copy after login

Note: Replace the following two sentences with your database name and your data table name


ALTER DATABASE your_database_name CHARACTER SET utf8 COLLATE utf8_general_ci 
 
ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
Copy after login

This ensures that the database is also in the utf-8 character set, and there will be no errors in querying the content in the database when inputting in Chinese.

reference:Illegal mix of collations MySQL Error

Set the database character set to utf-8 in PHP


mysqli_set_charset($dbc,'utf8');
Copy after login

in html Just add the meta that displays utf-8 in


<meta charset="utf-8">
Copy after login

Related recommendations:

Discuss about MySQL backup character set

php How to set the MySQL connection character set

MySQL character set and proofreading order usage tutorial

The above is the detailed content of Detailed explanation of mysql query character set mismatch problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template