doctrine dbal querybuilder as prepared statement(学说 dbal 查询构建器作为准备好的语句)
问题描述
我正在尝试创建一个 Doctrine DBAL 查询构建器对象并在其中设置一个参数.(使用 postgres db,dbal 2.3.4,学说
I'm trying to create a Doctrine DBAL querybuilder object and setting a parameter in it. (using a postgres db, dbal 2.3.4, doctrine
$connection = $this->_em->getConnection();
$qb = $connection->createQueryBuilder();
$qb->select('tbl_user_contract.pkid AS pkid');
$qb->from('tbl_user_contract', 'tbl_user_contract');
$qb->join('tbl_user_contract', 'tbl_user', 'tbl_user', 'tbl_user_contract.fk_user = tbl_user.pkid');
$qb->where('tbl_user.pkid = :userid');
$qb->setParameter(':userid', 10);
当我尝试获取此 querybuilder 对象的结果时,出现以下错误:
When I try to get the results of this querybuilder object I get the following error:
SQLSTATE[08P01]: <<Unknown error>>: 7 ERROR: bind message supplies 0 parameters,
but prepared statement "pdo_stmt_00000002" requires 1
当我检查 postgres 日志时,我看到查询通过,我注意到它需要一个参数,但我不会得到传入的参数.
When I check the postgres logs, I see the query passing by and I notice that it expects a parameter, but I won't get a parameter passed in.
我尝试在 where 表达式本身中设置 id(不使用准备好的语句),这奏效了.但我真的很想通过准备好的语句来实现这一点.
I tried to set the id in the where expression itself (without using prepared statements), that worked. But I really want to get this working with prepared statements.
有人知道如何解决这个问题吗?
Anyone knows how to solve this?
提前致谢
推荐答案
我认为你只需要从 setparameter
命令中删除冒号
I think you just need to remove colon from setparameter
command
$qb->setParameter('userid', 10);
至少它适用于 Doctrine help https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/query-builder.html
At least it works in Doctrine help https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/query-builder.html
这篇关于学说 dbal 查询构建器作为准备好的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:学说 dbal 查询构建器作为准备好的语句


基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01