I am trying to upload data from a Java app to a mySQL database encoded in utf8mb4 for all columns.
The Java app calls a PHP script to execute a store procedure to insert the data.
I expect the app to insert data in English, Kanji, Chinese or Greek
What's working:
===============
Uploading and inserting English data work as expected.
What's not working
==================
Uploading and inserting Chinese, Kanji, Greek etc resulted in this goobledygook mess 美人鱼-αβÏγτ-ἄλφα
The Java app is working as it is capturing and passing on the data to PHP.
The mySQL sproc likewise is working b/c it is inserting the data into the database, whether it is English or gobbledygook.
So I assume the problem is with encoding in PHP, here is the basic code
snippet:
<?php
$con = mysqli_connect("localhost", "username", "password", "dbinstance");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
con->query("SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci");
$coyName= $_POST['coyName'];
$result = "call sp_newCompany('$coyName')";
if(! mysqli_query($con, $result) ) {
die('Can not insert data: '.mysqli_error());
} else {
'New company $coyName inserted successfully<br/>\n';
}
mysqli_close($con);
?>
What I have tried sofar:
========================
I used JSON encode in Java app, then JSON_Decoe in PHP, but that did NOT resolve problem, I still got gobbledygook when I tried any language other than English.
Can someone pls point me in the right direction?
Maybe if I specify ASCII on upload from Java? I'll try that now.