PHP Mysql数据库中文乱码问题

php连接数据设置字符编码

$conn = new mysqli("127.0.0.1", "user", "pwd", "db_name");

$sql = "insert into test_db values('','这里是标题','这里是描述信息sss','url','图片地址','日期','11')";
//echo $sql;
$conn->query("set character set 'utf8'");//读库
$conn->query("set names 'utf8'");//写库

实例







query("set character set 'utf8'");//读库
    $conn->query("set names 'utf8'");//写库

    $result = $conn->query($sql);

    $sql = "SELECT title,article_desc,article_img,article_url,category,time_stamps FROM test_db";
    $result = $conn->query($sql);

    echo '';
    echo '';

    $num_fields = $result->field_count;
    //var_dump($num_fields);
    $fields = $result->fetch_fields();
    //  var_dump($fields);

    echo '';
    for ($i = 0; $i < $num_fields; $i++) {
        echo '';
    }
    echo '';

    while ($row = $result->fetch_assoc()) {
        echo "";
        for ($j = 0; $j < $num_fields; $j++) {
            echo '';
        }
        echo "";
    }

    echo "
' . $fields[$i]->name . '
'; echo $row[$fields[$j]->name]; echo '
"; echo "
"; $conn->close(); } show_article();

你可能感兴趣的:(PHP Mysql数据库中文乱码问题)