I have some problem with parsing arabic text to mysql database. Here is what I do:
-
Parse text from app to php script
String address = ListActivity.urlZapis; try { address +="?lp=" + detal.lp + "&date=" + detal.date + "&name=" + URLEncoder.encode (detal.name, "UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } try { URI uriAddress = new URI(address.replace(" ", "%20")); address=uriAddress.toString(); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(address); httpClient.execute(httpPost); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); }
in php file I connect to mysql and send data
$connect = mysqli_connect("$host", "$username", "$password", "$db_name");
if(mysqli_connect_errno($connect))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
Then I see something like this in my phpmyadmin: name - ماكروي٠وكولار instead of arabic text. Collation of mysql is set to utf8_general_ci. When I enter arabic text by phpmyadmin, everything works fine. It appears in my app correctly, so I am sure there is something wrong with sending it to db.