Question:
How do I insert non-English characters into mySQL using PHP?
What I can do successfully:
All mySQL rows are utf8mb4 encoded. In mySQL and using my sproc instead of PHP, I can insert parametric values in Chinese, Greek, German etc successfully.
Likewise, if I use Java HTTPS connection to execute the PHP, as long as the values are in English, the inserts and updates are successful. The HTTPS connection to cloud mySQL is always successful.
This is the problem:
But if I use PHP, the inserts result in a mess. After insert, the row value looks a bit like this mess
¾Žäººé±¼-αβÏγτ-ἄλφα
I am using _POST for insert.
Here is the PHP script:
<?php
$con = mysqli_connect("localhost", "username", "pwd", "instance");
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
$coyName= $_POST['cName'];
$result = "INSERT INTO Company(Name) VALUES ('$cName')";
if(! mysqli_query($con, $result) ) {
die('PHP cannot insert data! ' . mysqli_error());
} else {
'New company $cName inserted successfully<br/>\n';
}
mysqli_close($con);
?>