$this->db->escape怎么不起作用?
$sql="select * from test where username='".$this->db->escape($username)."'";上面这个sql加了$this->db->escape()和没加一样的效果但换成$this->db->escape_str()就OK,为什么? 因为程序大多使用的是$this->db->query(); $this->db->escape() 这个函数将会确定数据类型,以便仅对字符串类型数据进行转义。它将会自动增加单引号(single quotes)在数据的周围,所以你不能这样做:
$sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")";
哪需要怎么做? function escape($str)
{
if (is_string($str))
{
$str = "'".$this->escape_str($str)."'";
} 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
哈意思 他的意思是说 escape 如果传递的是字符串会自动调用 escape_str
楼主应该看一下源码就都解决了,很简单的源码。 :lol hex正解 了解。:lol
页:
[1]