longjianghu 发表于 2009-10-28 23:41:44

$this->db->escape怎么不起作用?

$sql="select * from test where username='".$this->db->escape($username)."'";
上面这个sql加了$this->db->escape()和没加一样的效果但换成$this->db->escape_str()就OK,为什么?

longjianghu 发表于 2009-10-28 23:43:35

因为程序大多使用的是$this->db->query();

longjianghu 发表于 2009-10-28 23:50:56

$this->db->escape() 这个函数将会确定数据类型,以便仅对字符串类型数据进行转义。它将会自动增加单引号(single quotes)在数据的周围,所以你不能这样做:
$sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")";
哪需要怎么做?

visvoy 发表于 2009-10-28 23:59:51

function escape($str)
        {
                if (is_string($str))
                {
                        $str = "'".$this->escape_str($str)."'";
                }

longjianghu 发表于 2009-10-29 09:44:51

function escape($str)
      {
                if (is_string($str))
                {
                        $str = "'".$this->escape_str($str)."'";
                } ...
visvoy 发表于 2009-10-28 23:59 http://codeigniter.org.cn/forums/images/common/back.gif


    哈意思

Hex 发表于 2009-10-29 10:09:29

他的意思是说 escape 如果传递的是字符串会自动调用 escape_str
楼主应该看一下源码就都解决了,很简单的源码。

visvoy 发表于 2009-10-29 11:51:29

:lol hex正解

longjianghu 发表于 2009-10-29 13:39:48

了解。:lol
页: [1]
查看完整版本: $this->db->escape怎么不起作用?