Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top