简体   繁体   中英

php file character encoding, mysql database character encoding, special characters

I've a mysql db with some special characters, an input form, some php pages.

  • In my first php page (requestPage) I have the input form.

  • This page sends (through GET) a parameter to an other php page (ResultsPage).

  • At last this php page (ResultsPage) send a query with the parameter to the dbms and shows results.


RequestPage is encoded as utf-8 through

  • meta http-equiv="Content-Type" content="text/html; charset=utf-8

ResultsPage is encoded as utf-8 through

  • meta http-equiv="Content-Type" content="text/html; charset=utf-8
  • header('Content-type: text/html; charset=utf-8');

The database and its tables are encoded as utf8_general_ci.


Now, for instance:

  • if I put in the form of RequestPage the word "Cantu", the resultsPage executes the query and show me every entry of the DB with the word "Cantù" and for me its OK.
  • If I put in the form of RequestPage the word "Cantù", the resultsPage executes the query and show me no rows but I want to see the rows with the word "Cantù"!

Any suggestion?

I've solved the problem with this string added in the php resultsPage file:

mysql_query("SET character_set_results = 'utf8', character_set_client='utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $connection);

Obviously it has to be inserted after this string:

$connection = mysql_connect($servername,$username,$dbpassword);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM