Maison >développement back-end >tutoriel php >ci 这样插入mysql,中文为什么显示空白.

ci 这样插入mysql,中文为什么显示空白.

WBOY
WBOYoriginal
2016-06-06 20:31:361370parcourir

<code>function insert_file($fwqm, $kjsj, $yxts, $jingyan, $version, $xianlu, $kefu, $zhuye)  
    {           
        $this->db->query("SET NAMES utf8"); 
        if($fwqm != null){
            $data = array(
                                    'fwqm' => $this->security->xss_clean($fwqm),
                                    'kjsj' => $this->security->xss_clean($kjsj),
                                    'yxts' => $this->security->xss_clean($yxts),
                                    'version' => $this->security->xss_clean($version),
                                    'jingyan' => $this->security->xss_clean($jingyan),
                                    'xianlu' => $this->security->xss_clean($xianlu),
                                    'kefu' => $this->security->xss_clean($kefu),
                                    'zhuye' => $this->security->xss_clean($zhuye),
                            );

             $this->db->insert('fbz',$data);
        }
    }
</code>

直接写中文是可以的,把变量赋值为中文也是可以插入的,通过表单也能插入,但就是这样通过参数传递进来,中文就插入不进mysql,显示空白.

知道了。编码问题
$kjsj = mb_convert_encoding($kjsj,'utf8', 'gbk');

回复内容:

<code>function insert_file($fwqm, $kjsj, $yxts, $jingyan, $version, $xianlu, $kefu, $zhuye)  
    {           
        $this->db->query("SET NAMES utf8"); 
        if($fwqm != null){
            $data = array(
                                    'fwqm' => $this->security->xss_clean($fwqm),
                                    'kjsj' => $this->security->xss_clean($kjsj),
                                    'yxts' => $this->security->xss_clean($yxts),
                                    'version' => $this->security->xss_clean($version),
                                    'jingyan' => $this->security->xss_clean($jingyan),
                                    'xianlu' => $this->security->xss_clean($xianlu),
                                    'kefu' => $this->security->xss_clean($kefu),
                                    'zhuye' => $this->security->xss_clean($zhuye),
                            );

             $this->db->insert('fbz',$data);
        }
    }
</code>

直接写中文是可以的,把变量赋值为中文也是可以插入的,通过表单也能插入,但就是这样通过参数传递进来,中文就插入不进mysql,显示空白.

知道了。编码问题
$kjsj = mb_convert_encoding($kjsj,'utf8', 'gbk');

你打印一下$data看看$this->security->xss_clean有没有接收到值。

你看下sql语句

<code>echo $this->db->last_query();
</code>
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn