문제

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