How to insert รถ / รค / รผ into a database using php utf8

I was asked a dozen times, but I only want to insert a German letter of type "ร„" into the database using php script, which simply does not work using existing solutions.

<?php header('Content-type: text/html; charset=utf-8'); $con = mysqli_connect("localhost", "username", "password"); mysqli_set_charset($con, "utf8mb4"); mysqli_select_db($con, "database"); mysqli_query($con, "SET SESSION CHARACTER_SET_RESULTS =utf8mb4;"); mysqli_query($con, "SET SESSION CHARACTER_SET_CLIENT =utf8mb4;"); mysqli_query($con, "SET NAMES 'utf8mb4';"); mysqli_query($con, "SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8';"); $title = 'ร–'; $result = mysqli_query($con, "INSERT INTO Test (Title) VALUES ('" . utf8_encode($title) . "');"); #Doesn't work, this was inserted: รƒ ?> 

The wrapper for the Header column is utf8mb4_general_ci, and the table itself is utf8_general_ci. MySQL server version is 5.5.31 MySQL Charset UTF-8 Unicode

Does anyone know what I'm doing wrong, or am I missing something here?

+5
source share
1 answer

As Mihai said, I had to remove the utf8_encode () function, which messed up the encoding. After removing it, it works as smoothly as it should.

0
source

Source: https://habr.com/ru/post/1212296/


All Articles