Category:

Change the encoding of MySQL using php

php_mysql_logo

After moving the site to permanent hosting on the Internet, I saw that the information-which is taken from the database instead of the characters displayed: "????????????"

Problem solution. In the database connection file, assign the desired encoding:

<?php
$db = mysql_connect ("DB_HOST","LOGIN","PASSWORD");
mysql_select_db("DATABASE_NAME", $variable to this request);

mysql_query("SET NAMES 'cp1251'");
mysql_query("SET CHARACTER SET 'cp1251'");
?>

After that, the information from the database is displayed in the correct encoding.


Posted: 2013-02-20

Comments