我有一个用于储存国名和货币象征的神秘数据库表——CHARSET正确地将国家名称和货币编号定为UTF8。
表格中的数据就是一个例子。
insert into country ( country_name, currency_name, currency_code, currency_symbol) values ( UK , Pounds , GBP , £ );
当我看数据库时——英镑的象征似乎是罚款的——但当我从数据库中取回,并在网站上显示时,一个圆形的方括号显示,在座标上,而不是在纸面上标出。
Edit In my.cnf - the characterset was set to latin1 - I changed it to utf8 - then I Logged in as root and ran s - it returned
Server characterset: utf8 Client characterset: utf8
讨论会
-- Database SELECT default_collation_name FROM information_schema.schemata WHERE schema_name = swipe_prod ; THIS DOES NOT RETURN ANYTHING -- Table SELECT table_collation FROM information_schema.tables WHERE TABLE_NAME = country ; THIS RETURNS utf8_general_ci -- Columns SELECT collation_name FROM information_schema.columns WHERE TABLE_NAME = country ; THIS RETURNS 7 ROWS but all have either null or utf8_general_ci
PHP CODE
<?php $con = mysql_connect("localhost","user","123456"); mysql_select_db("swipe_db", $con); $result = mysql_query("SELECT * FROM country where country_name= UK "); while($row = mysql_fetch_array($result)) { echo $row[ country_name ] . " " . $row[ currency_symbol ]; } mysql_close($con); ?>
Please advice Thanks