【问题标题】:removing quotes created by $this->db->escape without messing out original text删除 $this->db->e​​scape 创建的引号而不弄乱原始文本
【发布时间】:2015-03-07 08:37:47
【问题描述】:

在我的数据库中插入数据之前,我使用$this->db->escape,但是,当我在数据库中查询该数据时,我无法摆脱引号。

我正在使用str_replace("'", "",$p->post_text);,但它按预期删除了所有单引号。如果$p->post_text 是一个字符串,比如“我不再为玛丽的兄弟工作” 它也会删除这些。我注意到反斜杠被添加到字符串上的单引号中,而不是由 php 生成的单引号中。

所以我尝试了:

 $post_text = str_replace("'", "",$p->post_text);
 $post_text1 = stripslashes($post_text);

还是不行。我猜斜线会被自动剥离。

任何帮助将不胜感激。

更新添加的插入查询:

 $data = array('aluno_id' => $myid,
               'post_text' => $this->db->escape($text),
               'post_image' => $this->db->escape($img),
               'youtube_link' => $this->db->escape($video_code),
               'media_top' => $this->db->escape($media_top),
               'post_date' => date(date('Y-m-d H:i:s')) 

                            );

 $this->db->insert('mutamba_posts',$data);

【问题讨论】:

  • 你的插入命令怎么样?
  • 等等,当你像这样通过它时,CI 会让你逃避东西吗?这似乎搞砸了。我认为它会为你逃跑。
  • @cHao 我通常只做'post_text' => $text,但我在elislab 上读到使用$this->db->escape 逃避它更安全。
  • 对。 escape 用于手动构建查询等。请参阅ellislab.com/codeigniter/user-guide/database/…,尤其是本节末尾的红色框。他们正在转义您传递给insert 的数据,因此您不应该自己转义。
  • @cHao 我知道!此页面ellislab.com/codeigniter/user-guide/database/… 让我有些困惑,感谢您的快速回复;)

标签: php codeigniter quotes


【解决方案1】:

虽然这是一个老问题,但没有解决方案,所以我添加了这个。

尝试使用

$this->db->escape_str($YOUR_STRING);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    • 2022-07-06
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    相关资源
    最近更新 更多