【问题标题】:update in Doctrine with special characters使用特殊字符更新 Doctrine
【发布时间】:2015-04-16 08:15:09
【问题描述】:

当我尝试使用特殊字符更新我的值时出现此错误

消息:SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 't' WHERE (idcommentaire = 117)' 附近使用正确的语法。失败的查询:“UPDATE commentaire SET commentaire = 'test't' WHERE (idcommentaire = 117 )"

UPDATE commentaire SET commentaire = 'test't' WHERE (idcommentaire = 117)
                                          ^

为什么学说不管理特殊字符?

我的功能:

static public function modifierCommentaire($id, $commentaire)
{
    $req = Doctrine_Query::create()
    ->update('Commentaire c')
    ->set('c.commentaire ', $commentaire)
    ->where("c.idcommentaire=$id")
    ->execute();
}

【问题讨论】:

    标签: php doctrine doctrine-1.2


    【解决方案1】:

    您应该使用准备好的语句,并且更新查询应该如下所示:

    Doctrine_Query::create()
      ->update('Commentaire c')
      ->set('c.commentaire', '?', $commentaire)
      ->where('c.idcommentaire = ?', $id)
      ->execute();
    

    所以你有一个变量放一个?在那里并将参数作为参数传递。这样,学说将创建准备好的语句,并且变量将被正确转义(而且效率也更高)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-12
      • 2015-09-08
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多