简体   繁体   English

如何将汉字插入数据库

[英]How to insert chinese character into database

i am trying to add Chinese character in my database. 我正在尝试在数据库中添加汉字。 I am adding this 黔西南布依族苗族自治州 and getting this 黔西å—布ä¾æ any help? 我要添加此黔西南布依族苗族自治州,并获得此黔西å—布ä¾æ的帮助吗?

header('Content-Type: text/html; charset=utf-16');

header('Content-Type: text/html; charset=utf-8');  

if(isset($_POST['totalprice'])){

        $totalprice=$_POST['totalprice'];
        $price=$_POST['price'];
        $qty=$_POST['count'];
        $color=$_POST['color'];
        $name=$_POST['name'];
        $phone=$_POST['phone'];
        $address=$_POST['address'];
        $province=$_POST['province'];
        $city=$_POST['city'];
        $region=$_POST['region'];
        $payment=$_POST['payment'];
        $message=$_POST['message'];
        $model=$_POST['model'];
        $commodity=$_POST['commodity'];
        $totalprice=$_POST['totalprice'];
        $name=$_POST['name'];
        $description='';

        $sql="INSERT INTO `orderItems`( `commodity`, `model`, `color`, `qty`, `total`) VALUES ('$commodity','".$model."','".$color."','".$qty."','".$totalprice."')";
           $db->query($sql);
}

Please use utf8mb4 when you insert to table 插入表格时请使用utf8mb4

set username utf8mb4; INSERT INTO table_name (aaa,VAL);

you can just do it by alter table field from phpmyadmin and set type to utf8mb4 . 您可以通过从phpmyadmin更改表字段并将类型设置为utf8mb4完成此操作

mysqli_query("SET character_set_results=utf8mb4", $db);

Sometimes MySQL's utf8 does not support.This is because of a small number of Chinese characters that require 4-byte UTF8 characters.So utf8mb4 used. 有时MySQL的utf8不支持,这是因为少数汉字需要4字节UTF8字符, 因此使用utf8mb4

change that column's charset/collection from Default charset to utf8 将该列的字符集/集合从默认字符集更改为utf8

then you can insert anything in that column 然后您可以在该列中插入任何内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM