Chinese does not display or display abnormal solution when php uses mysql database

If the problem mentioned in the title occurs, the problem needs to be solved from four levels

1 Whether the project file is utf8 encoded

  Right-click the project file->properties->Resource->Text file encoding->set to utf8

2 Whether the page content is utf8 encoded

  Add in the <head> tag

1
< meta  http-equiv="Content-Type" content="text/html; charset=UTF-8">

  The above two steps can basically solve the problem of displaying Chinese on the local page

3 Whether the database uses utf8 encoding

  If a database is used, the database should also be encoded with uft8, that is, when creating a table, the character set should be utf8

4 Whether to use ut8 encoding during transmission with the database

  The local page uses utf8 encoding, and the remote database also uses utf8 encoding, but there may be garbled Chinese characters, which requires utf8 encoding during the transmission process. The method is to execute after establishing a database connection.

1
2
3
mysql_query("set names 'utf8'");//在插入数据执行前添加
mysql_query( "set character_set_client=utf8" );
mysql_query( "set character_set_results=utf8" );

  The above solves the problem of Chinese garbled characters when using php and mysql. If it still can't be solved, I can't help it =. . =

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782294&siteId=291194637