I have been trying to import words with special characters into MySQL via PHP INSERT command and I either get ??? for each special character or everything after it is cut off.
I have read a lot on the Internet buy none of the solutions seems to be working.
So currently Coruña
from the script, inserts as Coru???a
in SQL with the code below:
$con=mysqli_connect("localhost","user",'pass','database');
$con->query("SET NAMES 'utf8' ");
$con->query("SET CHARACTER SET 'utf8'");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO tbl_state (id, statecode, statename,country)
VALUES (1, 'A Coruña', 'A Coruña', 'ES')");
mysqli_close($con);
My page encoding is content="text/html; charset=utf-8"
.
I have tried with utf8_general_ci
and utf8_spanish_ci
collation for both table and column in MySQL but no success.
Any experts who have come to this problem, what could be wrong?
Thank you!
Ok so instead of trying to input the data via PHP script, I inserted it directly from phpMyAdmin with an INSERT query.
For the data to output correct in PHP (without squares or question marks) I added this when making the connection:
$mysqli->query("SET NAMES 'utf8'");
All worked great!
Thank you for the help and if someone still find the answer on how to do it via PHP script it will be interesting to hear.