【问题标题】:Query with doctrine 1用教义查询 1
【发布时间】:2018-07-11 12:35:18
【问题描述】:

我尝试从运行良好的 phpMyAdmin 进行以下 sql 查询,并返回 1 个结果与学说 1,但我得到一个异常:

SQLSTATE[42S22]:未找到列:1054 Champ 'MOY1100' inconnu dans where 子句。查询失败:“从 acteur_unite WHERE 中选择 id_au code_unite = MOY1100 限制 1"

这里是使用 phpMyAdmin 的 sql 查询:

SELECT id_au FROM acteur_unite WHERE code_unite = 'MOY1100' LIMIT 1

这是我对教义的查询:

 public function getId($code_unite) {

        $con = Doctrine_Manager::getInstance()->connection();

        $st = $con->execute("select id_au FROM acteur_unite
            WHERE code_unite = $code_unite LIMIT 1");

        $id = null;
        // fetch query result
        $data = $st->fetch(PDO::FETCH_ASSOC);
        $id = $data['id_au'];
        return $id;
    }

我哪里错了?

提前非常感谢

【问题讨论】:

标签: sql doctrine symfony1 doctrine-1.2


【解决方案1】:

您似乎错过了 var $code_unite 的引用

  $st = $con->execute("select id_au FROM acteur_unite
        WHERE code_unite = '$code_unite' LIMIT 1");

但要小心在 sql 中使用 var .. 你有 sql injection 的风险。然后检查您的框架是否以正确的方式为 param_binding .. 避免这种风险

例如:

  $st = $con->execute("select id_au FROM acteur_unite
    WHERE code_unite = :code_unite LIMIT 1");

  $st->bindParam(':code_unite', $code_unite, PDO::PARAM_STR);

【讨论】:

  • 感谢您的回复,我现在试试!我使用 symfony 1
猜你喜欢
  • 2012-01-06
  • 1970-01-01
  • 2014-02-27
  • 2015-11-30
  • 2015-10-13
  • 1970-01-01
  • 2021-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多