I am attempting to place some japanese words inside a mysql table! Basically place 'こんにちは' using phpMyAdmin, the term is displayed fine from phpMyAdmin. But when I attempt to place it through php, as follow:
mysql_connect($Host, $User, $Password); mysql_select_db($Database); $qry = "INSERT INTO table VALUES (0 , 'こんにちは')"; echo mysql_query($qry);
In phpMyAdmin i see "ã“ã‚“ã«ã¡ã¯" ... why?
And when I attempt to fetch in the database:
$arr = mysql_fetch_array(mysql_query("SELECT * FROM table where id = 1")); echo $arr;
The browser shows nothing!!!
How do i solve?
Thanks ahead of time for the help!!!
My database collation is setup to utf8_general_ci
I don't have to display the output with an HTML page, however the japanese test is printed on the XML page whose encoding is setup to UTF-8.
$plist = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $plist .= "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"; $plist .= "<plist version=\"1.0\">\n"; $plist .= "<array>\n"; $plist .= "\t<dict>\n"; $plist .= "\t\t<key>test</key>\n"; $plist .= "\t\t<string>".$arr."</string>\n"; $plist .= "\t</dict>\n"; $plist .= "</array>\n"; $plist .= "</plist>"; echo $plist;
the creation of this code is:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>test</key> <string></string> </dict> </array> </plist>
So, there's no value for that key "test" ... so what can I actually do? Thanks!
~ SOLVED ~
Problems solved while using function mysql_set_charset() after hooking up towards the database!
do this prior to the place query
mysql_query("SET NAMES utf8");
Also unsure should you set the correct charset from the database, as well as the site.
Charset in HTML Mind section?
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
and/or something like that like
header( 'Content-Type: text/html; charset=utf-8' );
Followers can help you have more ideas how to get it done .. if something does not work commment back.
check more here on SO
you have to set you Database Charset to utf8 and database collation to utf8_general_ci (or any other utf8 collation) i quickly think your condition solved