I'm trying to print values from the database, containing countrylist. One of the fields in this database is cyrilic. My PHP script looks like this:

include_once("db.php");

$query = mysql_query ("SELECT * FROM country");
$row = mysql_fetch_array($query);

do {
    $id = strtolower($row["id"]);
    $value = ($row["runame"]);
    echo $id . " " . $value . '<br/>';
} while ($row = mysql_fetch_array ($query));

The output from this script looks like this:

ad ???????
ae ???????????? ???????? ???????
af ??????????
ag ??????? ? ???????
ai ????????

So, apparently I need to set UTF-8 for this PHP script... somehow... Does anyone know how to do this? Thank you for your time!

有帮助吗?

解决方案

Try using SET NAMES utf8 after connecting to MySQL:

mysql_query("SET NAMES utf8");

Or if you are using cp1251 in the database, set this encoding.

As the manual says:

SET NAMES indicates what character set the client will use to send SQL statements to the server... It also specifies the character set that the server should use for sending results back to the client.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top