【问题标题】:How do you bind parameters when using Doctrine's EntityRepository::matching() method with a Criteria object?将 Doctrine 的 EntityRepository::matching() 方法与 Criteria 对象一起使用时,如何绑定参数?
【发布时间】:2021-11-19 13:58:13
【问题描述】:

我正在尝试使用Criteria 对象和EntityRepository::matching() 方法来查询我的数据库:

$criteria = new Criteria();
$criteria->where(Criteria::expr()->eq('applied', false))
         ->andWhere(Criteria::expr()->eq('cancelled', false))
         ->andWhere(Criteria::expr()->eq('identifier', $identifier)) // danger Here

        ;

$results = $this->matching($criteria);

问题是,标准参数之一可能来自最终用户(具体来说是$identifier)。

Criteriamatching(Criteria) 似乎不允许设置和绑定参数。

如何安全地执行这些查询?是否为使用EntityRepository::matching() 执行的任何查询自动绑定参数?

【问题讨论】:

    标签: php doctrine-orm doctrine sql-injection


    【解决方案1】:

    为此使用expr()->literal($identifier),它确保参数被正确转义。

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2016-04-01
      • 2017-06-07
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      相关资源
      最近更新 更多