This article mainly introduces the content of the PHP connection MySQL database after the garbled problem, has a certain reference value, now share to everyone, the need for friends can refer to
In general, there are two cases of Chinese garbled:
One: PHP code and Database encoding method is inconsistent:
General solution to this problem: Reset the database encoding format:
How to solve the problem: 1. Change the encoding format of the database configuration file to match the encoding format used in your PHP code.
2. After fetching the $conn value, give the returned object (Resource) $conn set the encoding format (for example, character encoding Utf-8): Mysqli_set_charset ($conn, "Utf-8").
Two: PHP code used in the encoding format and the browser decoding the encoding format inconsistent:
Workaround: Set the browser's decoding method in the returned HTTP response message.
Specific ways to solve the problem: 1. Add code at the beginning of the file: header ("Content-type:text/html;charset:utf-8")