Answer the question
In order to leave comments, you need to log in
Why does the encoding get lost when writing to MYSQL?
Hello, there is a news parsing page using html dom parser. For more than 2 months everything was fine, until today the encoding magically got lost.
On the parsing page, everything is fine, as soon as the string enters the database, we get (Многодетные СЃР) crocozyabrs. Before that everything was fine. All pages with parsing and output are utf-8 encoded. utf-8-general-ci is set in the database. Who faced or who can suggest a solution?
Answer the question
In order to leave comments, you need to log in
In 2019 mysql_query() has been deprecated. Use the same, only through mysqli_query().
Example:
$conn = mysqli_connect($servername, $username, $password, $database); //подключение к БД через mysqli_connect
mysqli_query($conn,"SET NAMES UTF8");
mysqli_query($conn,"SET CHARACTER SET UTF8");
Fixed everything, maybe it will be useful for someone. I don’t know why the encoding went wrong, but I solved the problem as follows, after connecting to the database I wrote two lines
mysql_query("SET NAMES UTF8");
mysql_query("SET CHARACTER SET UTF8");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question