使用特殊字符的Codeigniter MySQL查询 [英] Codeigniter mysql query with special characters

查看:41
本文介绍了使用特殊字符的Codeigniter MySQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去数小时以来一直在为这件事情苦苦挣扎.希望有人可以帮助我.

Been struggling with this thing for hours now. Hopefully someone could help me out.

试图根据名字和姓氏从mysql获取数据.除非有ä或ö这样的特殊字符,否则一切正常.

Trying to get data from mysql based on first and last name. Everything works just fine except when there is special characters like ä or ö.

我打开了探查器,查询看起来像这样:

I have the profiler on and query looks like this:

 SELECT mail, address, title FROM users WHERE firstname='teemu' AND lastname='sel%C3%A4nne'  

应该是:

SELECT mail, address, title FROM users WHERE firstname='teemu' AND lastname='selänne' 

在我的模型中是这样的:

In my model it's like this:

$sql = "SELECT mail, address, title FROM users WHERE firstname=? AND lastname=?";

我该如何解决?谢谢!

控制器

        public function edit() 
    {
        $this->load->model('p_model');
$this->load->view('edit',$data);
  }

public function ajax_p($first,$last)
  {
        $this->load->model('p_model');

$data['info'] = $this->p_model->pInfo($first,$last);

$this->load->view('ajax/p',$data);
    }

推荐答案

请确保您不要忘记对帖子值进行url解码.可能发生的是您使用$ _POST而不是代码点火器函数$ this-> input-> post();.$ _POST不会为您对参数进行url解码,而codeigniter函数可以.

Make sure you do not forget to urldecode the post values. What might be happening is that you use $_POST instead of the codeigniter function $this->input->post(); $_POST won't urldecode the parameters for you while the codeigniter function does.

因此,请确认您传递给查询的变量确实是selänne,而不是sel%C3%A4nne

So verify that the variable you pass to your query really is selänne and not sel%C3%A4nne

如果它是sel%C3%A4nne,请使用urldecode()或$ this-> input-> post()

And if it is sel%C3%A4nne, use urldecode() or $this->input->post()

这篇关于使用特殊字符的Codeigniter MySQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆