显示转义数据 [代码点火器]


displaying escaped data [codeigniter]

我正在使用$this->db->escape();将值保存在db

$this->db->set('last_name',$this->db->escape($lastname1));

它正在添加单引号,但我不想在视图中显示单引号。.有没有内置的方法可以做到这一点?

如果显示单引号,那么您可能会两次转义。我使用了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()'函数。

但是,将插入查询转义到数据库的常用方法是使用预准备语句。

正如我从文档中看到的,这个框架中没有真正的准备声明。但是,我发现这个:

$this->db->escape() 此函数 确定数据类型,以便 只能转义字符串数据。它还 自动添加单引号 围绕数据,因此您不必

您应该查看文档。