这是我在phpstorm中的代码。
MySQL数据库中的 Fname
是varchar
表的student
字段,其中包含波斯字符。我将DB排序设置为UTF8,但是,这段代码仍然让我回复#34; ??? ???"结果。
使用它有什么问题?
<?php
$conn = new PDO("mysql:host = localhost;dbname=university;charset = utf8","root","");
$query = "SELECT * FROM student WHERE status = 1";
$result = $conn->query($query);
while($row = $result->fetch(PDO::FETCH_ASSOC)){
echo $row['Fname'],"<br>";
}
?>
答案 0 :(得分:0)
尝试
$conn = new PDO("mysql:host=localhost;dbname=university;charset=utf8","root","",
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
而不是
$conn = new PDO("mysql:host = localhost;dbname=university;charset = utf8","root","");