Recently I faced a UNICODE encoding problem in MySQL Insert statement using PHP. When I tried to insert Swedish characters in MySQL table,the swedish characters ö, å, Ä were converted to ambiguous symbols because collation character set automatically converted to UTF8, usually I set MySQL collation into “utf8_general_ci”.

At last I find a solution in PHP to solve that problem, by using “mb_convert_encoding” we can convert encoding type at the insertion time.

$field = mb_convert_encoding($field,"iso-8859-1","utf-8");
	
@mysql_query("insert into table (field) values ('$field')");

This function will also work for other unicode character like spanish, Frecnch etc.

Advertisements