Reputation: 1651
When users try to save their name in german, they're saved like this:
Markus Müller ( Markus Müller)
Angela Eisenbl�tter ( Angela Eisenblätter )
Doris Vötter ( Doris Vötter )
I have inspected the values just before saving them with firebug and they show normally. But when saved they show like above. The structure of my table is this
name varchar(250) utf8_unicode_ci
email varchar(250) utf8_unicode_ci
company varchar(250) utf8_unicode_ci
reading int(11)
rdate timestamp
Please help me
update
$con=mysqli_connect("localhost","englisch_root","b00t","englisch_efront");
mysql_set_charset('utf8', $con);
after i have added like this it give fullowing error Warning: mysql_set_charset() expects parameter 2 to be resource,
Upvotes: 0
Views: 3072
Reputation: 788
First Read this http://www.joelonsoftware.com/articles/Unicode.html For clarity of encoding.
Then follow this article http://www.toptal.com/php/a-utf-8-primer-for-php-and-mysql
You need to ensured that you are using UTF-8 encoding at all the places Including. Html page, Database schema, table, column collation, Db Connection etc.
Upvotes: 0
Reputation: 142218
Two issues...
SELECT HEX(col), col FROM ... WHERE ...
-- For "Müller", you should get 4DC3BC6C6C6572
if it is correctly stored as utf8. If you don't get that, then you have either latin1 or a "double encoding", and fixing the data will be more complex.
If you are displaying this on a web page, you need a suitable tag near the top.
Upvotes: 0
Reputation: 464
User table column data is in ASCII instead of utf8_unicode_ci.
Upvotes: 0
Reputation: 4010
Replace mysql_set_charset('utf8');
with mysqli_set_charset($con, 'utf8');
(or $con->set_charset('utf8');
). You can't mix functions relative to databases of different PHP extensions (mysql vs mysqli): they work on different connections so they are mutually incompatible.
Notes:
utf8
, not utf-8
SET NAMES
statement, this is not safe:If you must change the character set of the connection, use the
mysql_set_character_set()
function rather than executing aSET NAMES
(orSET CHARACTER SET
) statement.mysql_set_character_set()
works likeSET NAMES
but also affects the character set used bymysql_real_escape_string()
, which SET NAMES does not.
(from MySQL's documentation about mysql_real_escape_string
, the C function behind mysql(i)_set_charset PHP functions)
Upvotes: 3
Reputation: 1669
Using mysqli_query($link,"SET CHARACTER SET utf8");
BEFORE the query solved the issue in my case. P.s. i suggest using mysqli_set_charset.
Upvotes: 0