I am developing an app with JAVA and PHP.
I call to the php file from the JAVA class, the php executes queries in the ddbb and returns the result. The problem is that it doesn’t return the characters correctly. I want to use UTF-8, I have in the beginning of my php file this:
header(“Content-type: text/html; charset=utf-8”);
but it doesn`t work. If I put a word directly with strange characters, and I do echo, the word appears correctly, but if I took them from the ddbb, it doesn’t.
The functions mb_internal_encoding returns ISO-8859-1 but if I set it to utf-8 doesnt work either
I don’t know if I explained correctly the problem, sorry for my english.
Thanks
You should prefer the following method if you have php 5.3.6+
The reason is that otherwise, string escaping won’t be handled properly. This is important because php still defaults to emulating prepared statements for mysql, so, it very heavily relies on the internal real_escape_string being able to identify the proper character set. Setting the character set via
"SET NAMES ..."will not update the internal character set setting that is used by real_escape_string.summary: you may be vulnerable to sql injection attacks if you don’t use the above method. I say may, because it depends on the initial and final charsets.
alternatively, you can configure pdo to not emulate prepared statements.
reference:
http://www.php.net/manual/en/mysqlinfo.concepts.charset.php