我使用$this->db->escape();
显示所逃脱数据[笨]
$this->db->set('last_name',$this->db->escape($lastname1));
它添加单引号现在的储蓄在分贝值,但我不想在views..is显示单有任何内置的如何做到这一点?
我使用$this->db->escape();
显示所逃脱数据[笨]
$this->db->set('last_name',$this->db->escape($lastname1));
它添加单引号现在的储蓄在分贝值,但我不想在views..is显示单有任何内置的如何做到这一点?
如果单引号显示,那么你可能会逃避两次。我已经使用escape
而没有在单引号上加倍。如果你看看http://www.codeignitor.com/user_guide/database/active_record.html,你会发现set
默认会自动转义。
set() will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE. To illustrate the difference, here is set() used both with and without the escape parameter.
所以你不需要调用escape
,你应该罚款。
我不知道你正在使用哪个类,因为来自PHP的MySQLI类没有任何'escape()' - 函数。
但是,将插入查询转义到数据库的常用方法是使用Prepared Statement。
正如我从文档中看到的,在此框架中没有真正的Prepared Statement。但是,我发现这一点:
$这个 - > DB->越狱()这个函数 确定数据类型,以便它 可以逃脱只有字符串数据。 它还 自动增加单引号 周围的数据,所以你不必:
您应该检查Documentation。
我检查了值在phpmyadmin中,看起来像set()不会添加单引号。但是当我使用escape()时,它添加单引号 – Vamsi 2011-05-07 19:10:52
因此,它接缝,使用escape()函数是毫无意义的,因为set()函数已经添加了单引号。 – 2011-05-07 19:17:46
'escape'在必要时加上单引号,否则不加单引号。 – Femi 2011-05-07 19:46:40